vendor/sulu/sulu/src/Sulu/Component/Content/Compat/StructureManager.php line 72

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Component\Content\Compat;
  11. use Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector;
  12. use Sulu\Component\Content\Compat\Structure\LegacyPropertyFactory;
  13. use Sulu\Component\Content\Metadata\Factory\Exception\StructureTypeNotFoundException;
  14. use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactory;
  15. use Sulu\Component\Content\Metadata\StructureMetadata;
  16. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  17. /**
  18.  * generates subclasses of structure to match template definitions.
  19.  * this classes will be cached in Symfony cache.
  20.  */
  21. class StructureManager implements StructureManagerInterface
  22. {
  23.     use ContainerAwareTrait;
  24.     private $structureFactory;
  25.     private $inspector;
  26.     private $propertyFactory;
  27.     private $typeMap;
  28.     public function __construct(
  29.         StructureMetadataFactory $structureFactory,
  30.         DocumentInspector $inspector,
  31.         LegacyPropertyFactory $propertyFactory,
  32.         array $typeMap
  33.     ) {
  34.         $this->structureFactory $structureFactory;
  35.         $this->inspector $inspector;
  36.         $this->propertyFactory $propertyFactory;
  37.         $this->typeMap $typeMap;
  38.     }
  39.     public function getStructure($key$type Structure::TYPE_PAGE)
  40.     {
  41.         try {
  42.             $metadata $this->structureFactory->getStructureMetadata($type$key);
  43.         } catch (StructureTypeNotFoundException $exception) {
  44.             return;
  45.         }
  46.         return $this->wrapStructure($type$metadata);
  47.     }
  48.     public function getStructures($type Structure::TYPE_PAGE)
  49.     {
  50.         $wrappedStructures = [];
  51.         $structures $this->structureFactory->getStructures($type);
  52.         foreach ($structures as $structure) {
  53.             $wrappedStructures[] = $this->wrapStructure($type$structure);
  54.         }
  55.         return $wrappedStructures;
  56.     }
  57.     public function wrapStructure($typeStructureMetadata $structure)
  58.     {
  59.         if (!isset($this->typeMap[$type])) {
  60.             throw new \InvalidArgumentException(
  61.                 \sprintf(
  62.                     'Invalid legacy type "%s", known types: "%s"',
  63.                     $type,
  64.                     \implode('", "', \array_keys($this->typeMap))
  65.                 )
  66.             );
  67.         }
  68.         $class $this->typeMap[$type];
  69.         return new $class($structure$this->inspector$this->propertyFactory);
  70.     }
  71. }