vendor/sulu/sulu/src/Sulu/Component/Webspace/Loader/XmlFileLoader11.php line 29

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\Webspace\Loader;
  11. use Sulu\Component\Webspace\Loader\Exception\ExpectedDefaultTemplatesNotFound;
  12. use Sulu\Component\Webspace\Webspace;
  13. /**
  14.  * This file loader is responsible for loading webspace configuration files using the xml format with the webspace
  15.  * schema version 1.1.
  16.  */
  17. class XmlFileLoader11 extends XmlFileLoader10
  18. {
  19.     public const SCHEMA_LOCATION '/schema/webspace/webspace-1.1.xsd';
  20.     public const SCHEMA_URI 'http://schemas.sulu.io/webspace/webspace-1.1.xsd';
  21.     protected function parseXml($file)
  22.     {
  23.         $webspace parent::parseXml($file);
  24.         $strategyNode $this->xpath->query('/x:webspace/x:resource-locator/x:strategy')->item(0);
  25.         if (null !== $strategyNode) {
  26.             $webspace->setResourceLocatorStrategy($strategyNode->nodeValue);
  27.         } else {
  28.             $webspace->setResourceLocatorStrategy('tree_leaf_edit');
  29.         }
  30.         $this->generateExcludedTemplates($webspace);
  31.         return $webspace;
  32.     }
  33.     protected function generateDefaultTemplates(Webspace $webspace)
  34.     {
  35.         $expected = ['page''home'];
  36.         foreach ($this->xpath->query('/x:webspace/x:default-templates/x:default-template') as $node) {
  37.             /* @var \DOMNode $node */
  38.             $template $node->nodeValue;
  39.             $type $node->attributes->getNamedItem('type')->nodeValue;
  40.             $webspace->addDefaultTemplate($type$template);
  41.             if ('homepage' === $type) {
  42.                 $webspace->addDefaultTemplate('home'$template);
  43.             }
  44.         }
  45.         $found \array_keys($webspace->getDefaultTemplates());
  46.         foreach ($expected as $item) {
  47.             if (!\in_array($item$found)) {
  48.                 throw new ExpectedDefaultTemplatesNotFound($this->webspace->getKey(), $expected$found);
  49.             }
  50.         }
  51.         return $webspace;
  52.     }
  53.     /**
  54.      * Adds the template for the given types as described in the XML document.
  55.      *
  56.      * The types can be arbitrary, so that another bundle can easily add a new type and use the information from the
  57.      * webspace.
  58.      *
  59.      * @return Webspace
  60.      */
  61.     protected function generateTemplates(Webspace $webspace)
  62.     {
  63.         foreach ($this->xpath->query('/x:webspace/x:templates/x:template') as $templateNode) {
  64.             /* @var \DOMNode $templateNode */
  65.             $template $templateNode->nodeValue;
  66.             $type $templateNode->attributes->getNamedItem('type')->nodeValue;
  67.             $webspace->addTemplate($type$template);
  68.         }
  69.         return $webspace;
  70.     }
  71.     /**
  72.      * Adds the excluded-templates as described in the XML document.
  73.      *
  74.      * @return Webspace
  75.      */
  76.     protected function generateExcludedTemplates(Webspace $webspace)
  77.     {
  78.         foreach ($this->xpath->query('/x:webspace/x:excluded-templates/x:excluded-template') as $excludedTemplateNode) {
  79.             /* @var \DOMNode $excludedTemplateNode */
  80.             $excludedTemplate $excludedTemplateNode->nodeValue;
  81.             $webspace->addExcludedTemplate($excludedTemplate);
  82.         }
  83.         return $webspace;
  84.     }
  85. }