public function loadPageConfigurationFromPhp($config, $configPath, $configPagePath)
{
// authorization
if (isset($config['authorization']) && is_array($config['authorization'])) {
$rules = array();
foreach ($config['authorization'] as $authorization) {
$patterns = isset($authorization['pages']) ? $authorization['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) {
$action = isset($authorization['action']) ? $authorization['action'] : '';
$users = isset($authorization['users']) ? $authorization['users'] : '';
$roles = isset($authorization['roles']) ? $authorization['roles'] : '';
$verb = isset($authorization['verb']) ? $authorization['verb'] : '';
$ips = isset($authorization['ips']) ? $authorization['ips'] : '';
$rules[] = new TAuthorizationRule($action, $users, $roles, $verb, $ips);
}
}
$this->_rules = array_merge($rules, $this->_rules);
}
// pages
if (isset($config['pages']) && is_array($config['pages'])) {
if (isset($config['pages']['properties'])) {
$this->_properties = array_merge($this->_properties, $config['pages']['properties']);
unset($config['pages']['properties']);
}
foreach ($config['pages'] as $id => $page) {
$properties = array();
if (isset($page['properties'])) {
$properties = $page['properties'];
unset($page['properties']);
}
$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);
}
}
}
// external configurations
if (isset($config['includes']) && is_array($config['includes'])) {
foreach ($config['includes'] as $include) {
$when = isset($include['when']) ? true : false;
if (!isset($include['file'])) {
throw new TConfigurationException('pageserviceconf_includefile_required');
}
$filePath = $include['file'];
if (isset($this->_includes[$filePath])) {
$this->_includes[$filePath] = array($configPagePath, '(' . $this->_includes[$filePath][1] . ') || (' . $when . ')');
} else {
$this->_includes[$filePath] = array($configPagePath, $when);
}
}
}
}