comparison core/modules/serialization/src/EntityResolver/ChainEntityResolver.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\serialization\EntityResolver;
4
5 use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
6
7 /**
8 * Resolver delegating the entity resolution to a chain of resolvers.
9 */
10 class ChainEntityResolver implements ChainEntityResolverInterface {
11
12 /**
13 * The concrete resolvers.
14 *
15 * @var \Drupal\serialization\EntityResolver\EntityResolverInterface[]
16 */
17 protected $resolvers = [];
18
19 /**
20 * Constructs a ChainEntityResolver object.
21 *
22 * @param \Drupal\serialization\EntityResolver\EntityResolverInterface[] $resolvers
23 * The array of concrete resolvers.
24 */
25 public function __construct(array $resolvers = []) {
26 $this->resolvers = $resolvers;
27 }
28
29 /**
30 * {@inheritdoc}
31 */
32 public function addResolver(EntityResolverInterface $resolver) {
33 $this->resolvers[] = $resolver;
34 }
35
36 /**
37 * {@inheritdoc}
38 */
39 public function resolve(NormalizerInterface $normalizer, $data, $entity_type) {
40 foreach ($this->resolvers as $resolver) {
41 $resolved = $resolver->resolve($normalizer, $data, $entity_type);
42 if (isset($resolved)) {
43 return $resolved;
44 }
45 }
46 }
47
48 }