vendor/sulu/sulu/src/Sulu/Component/DocumentManager/Metadata/MetadataFactory.php line 80

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\DocumentManager\Metadata;
  11. use PHPCR\NodeInterface;
  12. use Sulu\Component\DocumentManager\Document\UnknownDocument;
  13. use Sulu\Component\DocumentManager\Metadata;
  14. use Sulu\Component\DocumentManager\MetadataFactoryInterface;
  15. /**
  16.  * This class fully implements the MetadataFactoryInterface by composing
  17.  * the "base" metadata factory and the node mxins.
  18.  */
  19. class MetadataFactory implements MetadataFactoryInterface
  20. {
  21.     /**
  22.      * @var MetadataFactoryInterface
  23.      */
  24.     private $metadataFactory;
  25.     public function __construct(MetadataFactoryInterface $metadataFactory)
  26.     {
  27.         $this->metadataFactory $metadataFactory;
  28.     }
  29.     public function getMetadataForAlias($alias)
  30.     {
  31.         return $this->metadataFactory->getMetadataForAlias($alias);
  32.     }
  33.     public function getMetadataForPhpcrType($phpcrType)
  34.     {
  35.         return $this->metadataFactory->getMetadataForPhpcrType($phpcrType);
  36.     }
  37.     public function hasMetadataForPhpcrType($phpcrType)
  38.     {
  39.         return $this->metadataFactory->hasMetadataForPhpcrType($phpcrType);
  40.     }
  41.     public function getMetadataForClass($class)
  42.     {
  43.         return $this->metadataFactory->getMetadataForClass($class);
  44.     }
  45.     public function hasMetadataForClass($class)
  46.     {
  47.         return $this->metadataFactory->hasMetadataForClass($class);
  48.     }
  49.     public function hasAlias($alias)
  50.     {
  51.         return $this->metadataFactory->hasAlias($alias);
  52.     }
  53.     public function getAliases()
  54.     {
  55.         return $this->metadataFactory->getAliases();
  56.     }
  57.     public function getMetadataForPhpcrNode(NodeInterface $node)
  58.     {
  59.         if (false === $node->hasProperty('jcr:mixinTypes')) {
  60.             return $this->getUnknownMetadata();
  61.         }
  62.         $mixinTypes = (array) $node->getPropertyValue('jcr:mixinTypes');
  63.         foreach ($mixinTypes as $mixinType) {
  64.             if (true == $this->metadataFactory->hasMetadataForPhpcrType($mixinType)) {
  65.                 return $this->metadataFactory->getMetadataForPhpcrType($mixinType);
  66.             }
  67.         }
  68.         return $this->getUnknownMetadata();
  69.     }
  70.     public function getAllMetadata()
  71.     {
  72.         return $this->metadataFactory->getAllMetadata();
  73.     }
  74.     /**
  75.      * @return Metadata
  76.      */
  77.     private function getUnknownMetadata()
  78.     {
  79.         $metadata = new Metadata();
  80.         $metadata->setAlias(null);
  81.         $metadata->setPhpcrType(null);
  82.         $metadata->setClass(UnknownDocument::class);
  83.         return $metadata;
  84.     }
  85. }