| @@ 27-50 (lines=24) @@ | ||
| 24 | use V8\Value; | |
| 25 | ||
| 26 | ||
| 27 | class ObjectExtractor implements PlainExtractorInterface | |
| 28 | { | |
| 29 | /** | |
| 30 |      * {@inheritdoc} | |
| 31 | */ | |
| 32 | public function extract(Context $context, Value $value, PlainExtractorDefinitionInterface $definition, ExtractorInterface $extractor) | |
| 33 |     { | |
| 34 |         if ($value instanceof ObjectValue) { | |
| 35 | ||
| 36 |             if ($definition->getNext()) { | |
| 37 | // we have value constraint | |
| 38 |                 try { | |
| 39 | return $extractor->extract($context, $value, $definition->getNext()); | |
| 40 |                 } catch (ExtractorException $e) { | |
| 41 |                     throw new ExtractorException('Object value constraint failed: ' . $e->getMessage()); | |
| 42 | } | |
| 43 | } | |
| 44 | ||
| 45 | return $value; | |
| 46 | } | |
| 47 | ||
| 48 |         throw new ExtractorException('Value must be of the type object, ' . $value->typeOf()->value() . ' given'); | |
| 49 | } | |
| 50 | } | |
| 51 | ||
| @@ 27-50 (lines=24) @@ | ||
| 24 | use V8\Value; | |
| 25 | ||
| 26 | ||
| 27 | class PrimitiveExtractor implements PlainExtractorInterface | |
| 28 | { | |
| 29 | /** | |
| 30 |      * {@inheritdoc} | |
| 31 | */ | |
| 32 | public function extract(Context $context, Value $value, PlainExtractorDefinitionInterface $definition, ExtractorInterface $extractor) | |
| 33 |     { | |
| 34 |         if ($value instanceof PrimitiveValue) { | |
| 35 | ||
| 36 |             if ($definition->getNext()) { | |
| 37 | // we have value constraint | |
| 38 |                 try { | |
| 39 | return $extractor->extract($context, $value, $definition->getNext()); | |
| 40 |                 } catch (ExtractorException $e) { | |
| 41 |                     throw new ExtractorException('Primitive value constraint failed: ' . $e->getMessage()); | |
| 42 | } | |
| 43 | } | |
| 44 | ||
| 45 | return $value->value(); | |
| 46 | } | |
| 47 | ||
| 48 |         throw new ExtractorException('Value must be of the type primitive, ' . $value->typeOf()->value() . ' given'); | |
| 49 | } | |
| 50 | } | |
| 51 | ||