@@ 34-43 (lines=10) @@ | ||
31 | * @param Context|callable $context |
|
32 | * @return static |
|
33 | */ |
|
34 | public static function fromArray(array $data, $context = null) |
|
35 | { |
|
36 | if (isset($data['code'])) { |
|
37 | $className = sprintf('\Commercetools\Core\Error\%sError', self::pascalCase($data['code'])); |
|
38 | if (class_exists($className)) { |
|
39 | return new $className($data, $context); |
|
40 | } |
|
41 | } |
|
42 | return new static($data, $context); |
|
43 | } |
|
44 | ||
45 | protected static function pascalCase($name) |
|
46 | { |
@@ 76-85 (lines=10) @@ | ||
73 | * @param Context|callable $context |
|
74 | * @return static |
|
75 | */ |
|
76 | public static function fromArray(array $data, $context = null) |
|
77 | { |
|
78 | if (isset($data['type'])) { |
|
79 | $className = '\Commercetools\Core\Model\Message\\' . ucfirst($data['type']) . 'Message'; |
|
80 | if (class_exists($className)) { |
|
81 | return new $className($data, $context); |
|
82 | } |
|
83 | } |
|
84 | return new static($data, $context); |
|
85 | } |
|
86 | } |
|
87 |