/** * Adds the template for the given types as described in the XML document. * * The types can be arbitrary, so that another bundle can easily add a new type and use the information from the * webspace. * * @param Webspace $webspace * * @return Webspace */ protected function generateTemplates(Webspace $webspace) { foreach ($this->xpath->query('/x:webspace/x:templates/x:template') as $templateNode) { /* @var \DOMNode $templateNode */ $template = $templateNode->nodeValue; $type = $templateNode->attributes->getNamedItem('type')->nodeValue; $webspace->addTemplate($type, $template); } return $webspace; }
/** * Generates the available template types for the given webspace. * * @param Webspace $webspace * * @return Webspace * * @throws InvalidAmountOfDefaultErrorTemplateException * @throws InvalidDefaultErrorTemplateException * @throws InvalidErrorTemplateException */ protected function generateTemplates(Webspace $webspace) { $defaultErrorTemplates = 0; foreach ($this->xpath->query('/x:webspace/x:theme/x:error-templates/x:error-template') as $errorTemplateNode) { /* @var \DOMNode $errorTemplateNode */ $template = $errorTemplateNode->nodeValue; if (($codeNode = $errorTemplateNode->attributes->getNamedItem('code')) !== null) { $webspace->addTemplate('error-' . $codeNode->nodeValue, $template); } elseif (($defaultNode = $errorTemplateNode->attributes->getNamedItem('default')) !== null) { $default = $defaultNode->nodeValue === 'true'; if (!$default) { throw new InvalidDefaultErrorTemplateException($template, $this->webspace->getKey()); } ++$defaultErrorTemplates; $webspace->addTemplate('error', $template); } else { throw new InvalidErrorTemplateException($template, $this->webspace->getKey()); } } // only one or none default error-template is legal if ($defaultErrorTemplates > 1) { throw new InvalidAmountOfDefaultErrorTemplateException($this->webspace->getKey()); } return $webspace; }