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

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. public function __construct(private MetadataFactoryInterface $metadataFactory)
  22. {
  23. }
  24. public function getMetadataForAlias($alias)
  25. {
  26. return $this->metadataFactory->getMetadataForAlias($alias);
  27. }
  28. public function getMetadataForPhpcrType($phpcrType)
  29. {
  30. return $this->metadataFactory->getMetadataForPhpcrType($phpcrType);
  31. }
  32. public function hasMetadataForPhpcrType($phpcrType)
  33. {
  34. return $this->metadataFactory->hasMetadataForPhpcrType($phpcrType);
  35. }
  36. public function getMetadataForClass($class)
  37. {
  38. return $this->metadataFactory->getMetadataForClass($class);
  39. }
  40. public function hasMetadataForClass($class)
  41. {
  42. return $this->metadataFactory->hasMetadataForClass($class);
  43. }
  44. public function hasAlias($alias)
  45. {
  46. return $this->metadataFactory->hasAlias($alias);
  47. }
  48. public function getAliases()
  49. {
  50. return $this->metadataFactory->getAliases();
  51. }
  52. public function getMetadataForPhpcrNode(NodeInterface $node)
  53. {
  54. if (false === $node->hasProperty('jcr:mixinTypes')) {
  55. return $this->getUnknownMetadata();
  56. }
  57. $mixinTypes = (array) $node->getPropertyValue('jcr:mixinTypes');
  58. foreach ($mixinTypes as $mixinType) {
  59. if (true == $this->metadataFactory->hasMetadataForPhpcrType($mixinType)) {
  60. return $this->metadataFactory->getMetadataForPhpcrType($mixinType);
  61. }
  62. }
  63. return $this->getUnknownMetadata();
  64. }
  65. public function getAllMetadata()
  66. {
  67. return $this->metadataFactory->getAllMetadata();
  68. }
  69. /**
  70. * @return Metadata
  71. */
  72. private function getUnknownMetadata()
  73. {
  74. $metadata = new Metadata();
  75. $metadata->setAlias(null);
  76. $metadata->setPhpcrType(null);
  77. $metadata->setClass(UnknownDocument::class);
  78. return $metadata;
  79. }
  80. }