Mercurial > hg > isophonics-drupal-site
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/serialization/src/EntityResolver/ChainEntityResolver.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,48 @@ +<?php + +namespace Drupal\serialization\EntityResolver; + +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; + +/** + * Resolver delegating the entity resolution to a chain of resolvers. + */ +class ChainEntityResolver implements ChainEntityResolverInterface { + + /** + * The concrete resolvers. + * + * @var \Drupal\serialization\EntityResolver\EntityResolverInterface[] + */ + protected $resolvers = []; + + /** + * Constructs a ChainEntityResolver object. + * + * @param \Drupal\serialization\EntityResolver\EntityResolverInterface[] $resolvers + * The array of concrete resolvers. + */ + public function __construct(array $resolvers = []) { + $this->resolvers = $resolvers; + } + + /** + * {@inheritdoc} + */ + public function addResolver(EntityResolverInterface $resolver) { + $this->resolvers[] = $resolver; + } + + /** + * {@inheritdoc} + */ + public function resolve(NormalizerInterface $normalizer, $data, $entity_type) { + foreach ($this->resolvers as $resolver) { + $resolved = $resolver->resolve($normalizer, $data, $entity_type); + if (isset($resolved)) { + return $resolved; + } + } + } + +}