| @@ 62-92 (lines=31) @@ | ||
| 59 | return $out; |
|
| 60 | } |
|
| 61 | ||
| 62 | if ($value instanceof ObjectValue) { |
|
| 63 | $own_properties = $value->getOwnPropertyNames($context); |
|
| 64 | ||
| 65 | $length = $own_properties->length(); |
|
| 66 | $isolate = $context->getIsolate(); |
|
| 67 | ||
| 68 | $out = []; |
|
| 69 | ||
| 70 | $next = $definition->getNext(); |
|
| 71 | ||
| 72 | for ($i = 0; $i < $length; $i++) { |
|
| 73 | /** @var \V8\PrimitiveValue $prop */ |
|
| 74 | $prop = $own_properties->get($context, new IntegerValue($isolate, $i)); |
|
| 75 | $item = $value->get($context, $prop); |
|
| 76 | ||
| 77 | $prop_name = $prop->value(); |
|
| 78 | ||
| 79 | if ($next) { |
|
| 80 | try { |
|
| 81 | $out[$prop_name] = $extractor->extract($context, $item, $definition); |
|
| 82 | } catch (ExtractorException $e) { |
|
| 83 | throw new ExtractorException("Failed to convert array item #{$prop_name}: " . $e->getMessage()); |
|
| 84 | } |
|
| 85 | } else { |
|
| 86 | $out[$prop_name] = $item; |
|
| 87 | } |
|
| 88 | } |
|
| 89 | ||
| 90 | return $out; |
|
| 91 | ||
| 92 | } |
|
| 93 | ||
| 94 | throw new ExtractorException('Value must be of array type, ' . $value->typeOf()->value() . ' given instead'); |
|
| 95 | } |
|
| @@ 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 | } |
|