vendor/sulu/headless-bundle/Content/ContentResolver.php line 42

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Sulu.
  5.  *
  6.  * (c) Sulu GmbH
  7.  *
  8.  * This source file is subject to the MIT license that is bundled
  9.  * with this source code in the file LICENSE.
  10.  */
  11. namespace Sulu\Bundle\HeadlessBundle\Content;
  12. use Sulu\Bundle\HeadlessBundle\Content\ContentTypeResolver\ContentTypeResolverInterface;
  13. use Sulu\Component\Content\Compat\PropertyInterface;
  14. class ContentResolver implements ContentResolverInterface
  15. {
  16.     /**
  17.      * @var ContentTypeResolverInterface[]
  18.      */
  19.     private $resolvers;
  20.     /**
  21.      * ContentResolver constructor.
  22.      *
  23.      * @param \Traversable<ContentTypeResolverInterface> $resolvers
  24.      */
  25.     public function __construct(\Traversable $resolvers)
  26.     {
  27.         $this->resolvers \iterator_to_array($resolvers);
  28.     }
  29.     public function resolve($dataPropertyInterface $propertystring $locale, array $attributes = []): ContentView
  30.     {
  31.         if (!\array_key_exists($property->getContentTypeName(), $this->resolvers)) {
  32.             return new ContentView($data);
  33.         }
  34.         return $this->resolvers[$property->getContentTypeName()]->resolve($data$property$locale$attributes);
  35.     }
  36. }