public loadPageConfigurationFromXml ( $dom, $configPath, $configPagePath ) |
public function loadPageConfigurationFromXml($dom, $configPath, $configPagePath)
{
// authorization
if (($authorizationNode = $dom->getElementByTagName('authorization')) !== null) {
$rules = array();
foreach ($authorizationNode->getElements() as $node) {
$patterns = $node->getAttribute('pages');
$ruleApplies = false;
if (empty($patterns) || trim($patterns) === '*') {
// null or empty string
$ruleApplies = true;
} else {
foreach (explode(',', $patterns) as $pattern) {
if (($pattern = trim($pattern)) !== '') {
// we know $configPagePath and $this->_pagePath
if ($configPagePath !== '') {
// prepend the pattern with ConfigPagePath
$pattern = $configPagePath . '.' . $pattern;
}
if (strcasecmp($pattern, $this->_pagePath) === 0) {
$ruleApplies = true;
break;
}
if ($pattern[strlen($pattern) - 1] === '*') {
if (strncasecmp($this->_pagePath, $pattern, strlen($pattern) - 1) === 0) {
$ruleApplies = true;
break;
}
}
}
}
}
if ($ruleApplies) {
$rules[] = new TAuthorizationRule($node->getTagName(), $node->getAttribute('users'), $node->getAttribute('roles'), $node->getAttribute('verb'), $node->getAttribute('ips'));
}
}
$this->_rules = array_merge($rules, $this->_rules);
}
// pages
if (($pagesNode = $dom->getElementByTagName('pages')) !== null) {
$this->_properties = array_merge($this->_properties, $pagesNode->getAttributes()->toArray());
// at the page folder
foreach ($pagesNode->getElementsByTagName('page') as $node) {
$properties = $node->getAttributes();
$id = $properties->remove('id');
if (empty($id)) {
throw new TConfigurationException('pageserviceconf_page_invalid', $configPath);
}
$matching = false;
$id = $configPagePath === '' ? $id : $configPagePath . '.' . $id;
if (strcasecmp($id, $this->_pagePath) === 0) {
$matching = true;
} else {
if ($id[strlen($id) - 1] === '*') {
// try wildcard matching
$matching = strncasecmp($this->_pagePath, $id, strlen($id) - 1) === 0;
}
}
if ($matching) {
$this->_properties = array_merge($this->_properties, $properties->toArray());
}
}
}
// external configurations
foreach ($dom->getElementsByTagName('include') as $node) {
if (($when = $node->getAttribute('when')) === null) {
$when = true;
}
if (($filePath = $node->getAttribute('file')) === null) {
throw new TConfigurationException('pageserviceconf_includefile_required');
}
if (isset($this->_includes[$filePath])) {
$this->_includes[$filePath] = array($configPagePath, '(' . $this->_includes[$filePath][1] . ') || (' . $when . ')');
} else {
$this->_includes[$filePath] = array($configPagePath, $when);
}
}
}
/** * Collects configuration for a page. * @param TXmlElement additional configuration specified in the application configuration * @return TPageConfiguration */ protected function loadPageConfig($config) { $application = $this->getApplication(); $pagePath = $this->getRequestedPagePath(); if (($cache = $application->getCache()) === null) { $pageConfig = new TPageConfiguration($pagePath); if ($config !== null) { if ($application->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) { $pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), ''); } else { $pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), ''); } } $pageConfig->loadFromFiles($this->getBasePath()); } else { $configCached = true; $currentTimestamp = array(); $arr = $cache->get(self::CONFIG_CACHE_PREFIX . $this->getID() . $pagePath); if (is_array($arr)) { list($pageConfig, $timestamps) = $arr; if ($application->getMode() !== TApplicationMode::Performance) { foreach ($timestamps as $fileName => $timestamp) { if ($fileName === 0) { $appConfigFile = $application->getConfigurationFile(); $currentTimestamp[0] = $appConfigFile === null ? 0 : @filemtime($appConfigFile); if ($currentTimestamp[0] > $timestamp || $timestamp > 0 && !$currentTimestamp[0]) { $configCached = false; } } else { $currentTimestamp[$fileName] = @filemtime($fileName); if ($currentTimestamp[$fileName] > $timestamp || $timestamp > 0 && !$currentTimestamp[$fileName]) { $configCached = false; } } } } } else { $configCached = false; $paths = explode('.', $pagePath); $configPath = $this->getBasePath(); $fileName = $this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP ? self::CONFIG_FILE_PHP : self::CONFIG_FILE_XML; foreach ($paths as $path) { $configFile = $configPath . DIRECTORY_SEPARATOR . $fileName; $currentTimestamp[$configFile] = @filemtime($configFile); $configPath .= DIRECTORY_SEPARATOR . $path; } $appConfigFile = $application->getConfigurationFile(); $currentTimestamp[0] = $appConfigFile === null ? 0 : @filemtime($appConfigFile); } if (!$configCached) { $pageConfig = new TPageConfiguration($pagePath); if ($config !== null) { if ($application->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) { $pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), ''); } else { $pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), ''); } } $pageConfig->loadFromFiles($this->getBasePath()); $cache->set(self::CONFIG_CACHE_PREFIX . $this->getID() . $pagePath, array($pageConfig, $currentTimestamp)); } } return $pageConfig; }