@@ 35-65 (lines=31) @@ | ||
32 | */ |
|
33 | public function extract(Context $context, Value $value, PlainExtractorDefinitionInterface $definition, ExtractorInterface $extractor) |
|
34 | { |
|
35 | if ($value instanceof ObjectValue) { |
|
36 | $own_properties = $value->getOwnPropertyNames($context); |
|
37 | ||
38 | $length = $own_properties->length(); |
|
39 | $isolate = $context->getIsolate(); |
|
40 | ||
41 | $out = []; |
|
42 | ||
43 | $next = $definition->getNext(); |
|
44 | ||
45 | for ($i = 0; $i < $length; $i++) { |
|
46 | /** @var \V8\PrimitiveValue $prop */ |
|
47 | $prop = $own_properties->get($context, new IntegerValue($isolate, $i)); |
|
48 | $item = $value->get($context, $prop); |
|
49 | ||
50 | $prop_name = $prop->value(); |
|
51 | ||
52 | if ($next) { |
|
53 | try { |
|
54 | $out[$prop_name] = $extractor->extract($context, $item, $definition); |
|
55 | } catch (ExtractorException $e) { |
|
56 | throw new ExtractorException("Failed to convert assoc item #{$prop_name}: " . $e->getMessage()); |
|
57 | } |
|
58 | } else { |
|
59 | $out[$prop_name] = $item; |
|
60 | } |
|
61 | } |
|
62 | ||
63 | return $out; |
|
64 | ||
65 | } |
|
66 | ||
67 | throw new ExtractorException('Value must be of object type, ' . $value->typeOf()->value() . ' given instead'); |
|
68 | } |
@@ 61-91 (lines=31) @@ | ||
58 | return $out; |
|
59 | } |
|
60 | ||
61 | if ($value instanceof ObjectValue) { |
|
62 | $own_properties = $value->getOwnPropertyNames($context); |
|
63 | ||
64 | $length = $own_properties->length(); |
|
65 | $isolate = $context->getIsolate(); |
|
66 | ||
67 | $out = []; |
|
68 | ||
69 | $next = $definition->getNext(); |
|
70 | ||
71 | for ($i = 0; $i < $length; $i++) { |
|
72 | /** @var \V8\PrimitiveValue $prop */ |
|
73 | $prop = $own_properties->get($context, new IntegerValue($isolate, $i)); |
|
74 | $item = $value->get($context, $prop); |
|
75 | ||
76 | $prop_name = $prop->value(); |
|
77 | ||
78 | if ($next) { |
|
79 | try { |
|
80 | $out[$prop_name] = $extractor->extract($context, $item, $definition); |
|
81 | } catch (ExtractorException $e) { |
|
82 | throw new ExtractorException("Failed to convert array item #{$prop_name}: " . $e->getMessage()); |
|
83 | } |
|
84 | } else { |
|
85 | $out[$prop_name] = $item; |
|
86 | } |
|
87 | } |
|
88 | ||
89 | return $out; |
|
90 | ||
91 | } |
|
92 | ||
93 | throw new ExtractorException('Value must be of array type, ' . $value->typeOf()->value() . ' given instead'); |
|
94 | } |