commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
lib
commercetools-base
src
Base
JsonObjectModel.php
1
<?php
2
3
declare(strict_types=1);
10
namespace
Commercetools\Base
;
11
12
use stdClass;
13
14
class
JsonObjectModel
extends
BaseJsonObject
implements
JsonObject
15
{
19
final
public
function
get
(
string
$field)
20
{
21
$data = $this->
raw
($field);
22
if
($data instanceof stdClass) {
23
return
JsonObjectModel::of
($data);
24
}
25
if
(is_array($data) && isset($data[0]) && $data[0] instanceof stdClass) {
27
return
new
JsonObjectCollection
($data);
28
}
29
return
$data;
30
}
31
32
final
protected
function
toArray
(): array
33
{
34
$data = array_filter(
35
get_object_vars($this),
40
function
($value) {
41
return
!is_null($value);
42
}
43
);
44
$data = array_replace($this->
getRawDataArray
(), $data);
45
return
$data;
46
}
47
51
public
function
with
(callable $callable =
null
)
52
{
53
if
(is_null($callable)) {
54
return
$this;
55
}
56
57
return
$callable($this);
58
}
59
}
Commercetools\Base\BaseJsonObject
Definition:
BaseJsonObject.php:18
Commercetools\Base\BaseJsonObject\raw
raw(string $field)
Definition:
BaseJsonObject.php:57
Commercetools\Base\BaseJsonObject\of
static of($data=null)
Definition:
BaseJsonObject.php:26
Commercetools\Base\BaseJsonObject\getRawDataArray
getRawDataArray()
Definition:
BaseJsonObject.php:78
Commercetools\Base\JsonObjectCollection
Definition:
JsonObjectCollection.php:20
Commercetools\Base\JsonObjectModel
Definition:
JsonObjectModel.php:15
Commercetools\Base\JsonObjectModel\with
with(callable $callable=null)
Definition:
JsonObjectModel.php:51
Commercetools\Base\JsonObjectModel\toArray
toArray()
Definition:
JsonObjectModel.php:32
Commercetools\Base\JsonObject
Definition:
JsonObject.php:15
Commercetools\Base
Definition:
MapperArraySequence.php:10
Generated by
1.9.1