@@ 27-53 (lines=27) @@ | ||
24 | use V8\Value; |
|
25 | ||
26 | ||
27 | class ArrayExtractor implements PlainExtractorInterface |
|
28 | { |
|
29 | /** |
|
30 | * @var AssocExtractor |
|
31 | */ |
|
32 | private $extractor; |
|
33 | ||
34 | /** |
|
35 | * @inheritDoc |
|
36 | */ |
|
37 | public function __construct(AssocExtractor $extractor) |
|
38 | { |
|
39 | $this->extractor = $extractor; |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * {@inheritdoc} |
|
44 | */ |
|
45 | public function extract(Context $context, Value $value, PlainExtractorDefinitionInterface $definition, ExtractorInterface $extractor) |
|
46 | { |
|
47 | if ($value instanceof ArrayObject) { |
|
48 | return $this->extractor->extract($context, $value, $definition, $extractor); |
|
49 | } |
|
50 | ||
51 | throw new ExtractorException('Value must be of array type, ' . $value->typeOf()->value() . ' given instead'); |
|
52 | } |
|
53 | } |
|
54 |
@@ 26-53 (lines=28) @@ | ||
23 | use V8\Value; |
|
24 | ||
25 | ||
26 | class ScalarExtractor implements PlainExtractorInterface |
|
27 | { |
|
28 | /** |
|
29 | * @var PlainExtractorInterface[] |
|
30 | */ |
|
31 | private $scalar_extractors; |
|
32 | ||
33 | public function __construct(PlainExtractorInterface ...$scalar_extractors) |
|
34 | { |
|
35 | $this->scalar_extractors = $scalar_extractors; |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * {@inheritdoc} |
|
40 | */ |
|
41 | public function extract(Context $context, Value $value, PlainExtractorDefinitionInterface $definition, ExtractorInterface $extractor) |
|
42 | { |
|
43 | foreach ($this->scalar_extractors as $scalar_extractor) { |
|
44 | try { |
|
45 | return $scalar_extractor->extract($context, $value, $definition, $extractor); |
|
46 | } catch (ExtractorException $e) { |
|
47 | // |
|
48 | } |
|
49 | } |
|
50 | ||
51 | throw new ExtractorException('Value must be of the type scalar or be able to be casted to scalar, ' . $value->typeOf()->value() . ' given'); |
|
52 | } |
|
53 | } |
|
54 |
@@ 26-53 (lines=28) @@ | ||
23 | use V8\Value; |
|
24 | ||
25 | ||
26 | class AnyExtractor implements PlainExtractorInterface |
|
27 | { |
|
28 | /** |
|
29 | * @var PlainExtractorInterface[] |
|
30 | */ |
|
31 | private $extractors; |
|
32 | ||
33 | public function __construct(PlainExtractorInterface ...$extractors) |
|
34 | { |
|
35 | $this->extractors = $extractors; |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * {@inheritdoc} |
|
40 | */ |
|
41 | public function extract(Context $context, Value $value, PlainExtractorDefinitionInterface $definition, ExtractorInterface $extractor) |
|
42 | { |
|
43 | foreach ($this->extractors as $plain_extractor) { |
|
44 | try { |
|
45 | return $plain_extractor->extract($context, $value, $definition, $extractor); |
|
46 | } catch (ExtractorException $e) { |
|
47 | // |
|
48 | } |
|
49 | } |
|
50 | ||
51 | throw new ExtractorException('Unable to pick proper extractor for ' . $value->typeOf()->value() . 'type'); |
|
52 | } |
|
53 | } |
|
54 |