private function &_createPermission(__ConfigurationSection &$permission_section) { $permission_id = strtoupper($permission_section->getAttribute('id')); if ($permission_id == 'PERMISSION_ALL') { throw new __ConfigurationException('Can not create a permission with name ' . $permission_id . ' reserved for an special permission'); } else { if (key_exists($permission_id, $this->_permission_ids)) { throw new __ConfigurationException('Double declaration of permission ' . $permission_id . '. If your intention was to reference an already existing permission, use a REF tag instead of PERMISSION'); } } $this->_permission_ids[$permission_id] = true; $subsections = $permission_section->getSections(); if (count($subsections) == 0) { $binary_representation = null; } else { $binary_representation = 0; } if ($permission_section->hasAttribute('class')) { $class = $permission_section->getAttribute('class'); } else { $class = '__Permission'; } if (class_exists($class)) { $permission = new $class($permission_id, $binary_representation); if (!$permission instanceof __Permission) { throw new __ConfigurationException('Unexpected class for permission: ' . $class); } } else { throw new __ConfigurationException('Unknown class for permission: ' . $class); } foreach ($subsections as $subsection) { if (strtoupper($subsection->getName()) == 'JUNIOR-PERMISSIONS') { $junior_permission_sections = $subsection->getSections(); foreach ($junior_permission_sections as $junior_permission_section) { switch (strtoupper($junior_permission_section->getName())) { case 'REF': $junior_permission_id = strtoupper($junior_permission_section->getAttribute('id')); if ($junior_permission_id == 'PERMISSION_ALL') { throw new __ConfigurationException('Special permission ' . $junior_permission_id . ' can not be referenced by a permission definition'); } if (key_exists($junior_permission_id, $this->_permissions)) { $junior_permission =& $this->_permissions[$junior_permission_id]; $permission->addJuniorPermission($junior_permission); unset($junior_permission); } else { throw new __ConfigurationException('Unknow permission reference: ' . $junior_permission_id . '. If the permission already exist but has been declared below the reference, move the declaration before the reference.'); } break; case 'PERMISSION': $junior_permission = $this->_createPermission($junior_permission_section); $this->_permissions[$junior_permission->getId()] =& $junior_permission; $permission->addJuniorPermission($junior_permission); unset($junior_permission); break; } } } } return $permission; }
/** * Create a child configuration component. * * @param integer $type Type of configuration component to be created * @param string $name Component name to be created * @param string $content Component content * @param array $attributes Component attributes * @param string $where Choose a position 'bottom', 'top', 'after', 'before' where the new component will be added * @param __ConfigurationComponent $target needed if you choose 'before' or 'after' for where * * @return __ConfigurationComponent A reference to the new component */ protected function &createComponent($type, $name, $content, array $attributes = array(), $where = 'bottom', __ConfigurationComponent $target = null) { switch ($type) { case __ConfigurationComponentType::SECTION: $component = new __ConfigurationSection($name, $content, $attributes); $section_handler = __SectionHandlerFactory::getInstance()->createSectionHandler($name); if ($section_handler != null) { $component->registerSectionHandler($section_handler); } break; case __ConfigurationComponentType::PROPERTY: $component = new __ConfigurationProperty($name, $content, $attributes); break; case __ConfigurationComponentType::COMMENT: $component = new __ConfigurationComment($name, $content, $attributes); break; case __ConfigurationComponentType::BLANK: $component = new __ConfigurationBlank($name, $content, $attributes); break; default: throw __ExceptionFactory::getInstance()->createException('ERR_UNKNOW_CONFIGURATION_COMPONENT_TYPE', array($type)); break; } $return_value =& $this->addComponent($component, $where, $target); return $return_value; }
public function &doProcess(__ConfigurationSection &$section) { $return_value = array('dynamic_rules' => array(), 'static_rules' => array()); $view_definition_sections = $section->getSections(); foreach ($view_definition_sections as $view_definition_section) { $view_definition = new __ViewDefinition(); $view_definition->setViewCode($view_definition_section->getAttribute('code')); $view_definition->setViewClass($view_definition_section->getAttribute('class')); $view_definition_subsections = $view_definition_section->getSections(); foreach ($view_definition_subsections as $view_definition_subsection) { switch (strtoupper($view_definition_subsection->getName())) { case 'PROPERTY': $property_name = $view_definition_subsection->getAttribute('name'); $property_value = $view_definition_subsection->getAttribute('value'); $view_definition->addProperty($property_name, $property_value); break; } } if (strpos($view_definition->getViewCode(), '*') !== false) { $clasify = 'dynamic_rules'; } else { $clasify = 'static_rules'; } $return_value[$clasify][strtoupper($view_definition->getViewCode())] =& $view_definition; unset($view_definition); } return $return_value; }
public function &doProcess(__ConfigurationSection &$section) { $return_value = array(); $stream_wrappers = $section->getSections(); foreach ($stream_wrappers as &$stream_wrapper) { $stream_wrapper_class = $stream_wrapper->getAttribute('stream-wrapper-class'); $return_value[$stream_wrapper->getAttribute('protocol')] = $stream_wrapper_class; } return $return_value; }
protected function _getResourceGroups(__ConfigurationSection &$section) { $return_value = array(); $i18n_resources_sections =& $section->getSections(); foreach ($i18n_resources_sections as &$i18n_resources_section) { if (strtoupper($i18n_resources_section->getName()) == 'RESOURCES-GROUP') { $return_value[] = $i18n_resources_section->getAttribute('id'); } } return $return_value; }
/** * Returns a collection of Foo instances according to * the configuration section. */ public function &process(__ConfigurationSection &$section) { $return_value = array(); $foobars = $section->getSections(); foreach ($foobars as &$foobar) { $foo = new Foo(); $foo->setBar($foobar->getAttribute('bar')); $return_value[] = $foo; } return $return_value; }
public function &doProcess(__ConfigurationSection &$section) { $languages = array(__ContextManager::getInstance()->getCurrentContext()->getPropertyContent('DEFAULT_LANG_ISO_CODE') => true); $subsections = $section->getSections(); foreach ($subsections as &$subsection) { if (strtoupper($subsection->getName()) == 'LANGUAGE') { $languages[$subsection->getProperty('#text')->getContent()] = true; } } $return_value = array_keys($languages); return $return_value; }
private function _setPermissions(__Role &$role, __ConfigurationSection &$section) { $permission_sections = $section->getSections(); foreach ($permission_sections as &$permission_section) { if (strtoupper($permission_section->getName()) == 'PERMISSION') { $permission_id = $permission_section->getAttribute('id'); $permission = __PermissionManager::getInstance()->getPermission($permission_id); $role->addPermission($permission); unset($permission); } } }
public function &doProcess(__ConfigurationSection &$section) { //initialize the return value with all the filter chains for all the available routes: $return_value = array(); $filter_sections = $section->getSections(); foreach ($filter_sections as &$filter_section) { $filter_name = $filter_section->getAttribute('name'); $filter_class = $filter_section->getAttribute('class'); $filter = new $filter_class(); if ($filter_section->hasAttribute('order')) { $filter->setOrder($filter_section->getAttribute('order')); } if ($filter_section->hasAttribute('execute-before-cache')) { $filter->setExecuteBeforeCache(__ConfigurationValueResolver::toBool($filter_section->getAttribute('execute-before-cache'))); } if ($filter instanceof __IFilter) { $routes_to_apply_to = $filter_section->getSection('apply-to'); if ($routes_to_apply_to != null) { $routes_to_apply_to_sections = $routes_to_apply_to->getSections(); foreach ($routes_to_apply_to_sections as $route_section) { switch (strtoupper($route_section->getName())) { case 'ALL-ROUTES': if (!key_exists('*', $return_value)) { $return_value['*'] = array(); } $return_value['*'][] =& $filter; break; case 'ROUTE': $route_id = $route_section->getAttribute('id'); if (!key_exists($route_id, $return_value)) { $return_value[$route_id] = new __FilterChain(); } $filter_chain =& $return_value[$route_id]; $filter_chain->addFilter($filter); unset($filter_chain); break; } } unset($routes_to_apply_to_sections); } unset($routes_to_apply_to); } else { throw __ExceptionFactory::getInstance()->createException('Unexpected class ' . get_class($filter) . '. A class implementing __IFilter was expected.'); } unset($filter); } return $return_value; }
private function &_loadResourceProvider(__ConfigurationSection &$section) { //Now will load resources provider for current __ResourceDictionary instance: $resource_provider_class = $section->getAttribute('class'); //and now create a new instance of readed class: $return_value = new $resource_provider_class(); switch (strtoupper($section->getAttribute('persistence-level'))) { case 'SESSION': $return_value->setPersistenceLevel(PERSISTENCE_LEVEL_SESSION); break; case 'ACTION': $return_value->setPersistenceLevel(PERSISTENCE_LEVEL_ACTION); break; default: $return_value->setPersistenceLevel($section->getAttribute('persistence-level')); break; } $return_value->setDescription($section->getAttribute('description')); $sub_sections = $section->getSections(); foreach ($sub_sections as &$sub_section) { switch (strtoupper($sub_section->getName())) { case 'RESOURCES-TYPE': $return_value->setResourceType($sub_section->getAttribute('class')); break; case 'PROPERTIES': $properties_sub_sections = $sub_section->getSections(); foreach ($properties_sub_sections as $property_sub_section) { $property_name = $property_sub_section->getAttribute('name'); $property_value = $property_sub_section->getAttribute('value'); $setter = 'set' . ucfirst($property_name); if (method_exists($return_value, $setter)) { $return_value->{$setter}($property_value); } else { throw new __ConfigurationException('Error found on resource-providers configuration section: Setter not found on ' . get_class($return_value) . ': ' . $setter); } } break; } } return $return_value; }
protected function &_createRoute(__ConfigurationSection &$section) { $route = new __Route(); $route->setId($section->getAttribute('id')); if ($section->hasAttribute('supercache')) { $route->setSuperCache(__ConfigurationValueResolver::toBool($section->getAttribute('supercache'))); } else { if ($section->hasAttribute('cache')) { $route->setCache(__ConfigurationValueResolver::toBool($section->getAttribute('cache'))); } } if ($section->hasAttribute('order')) { $route->setOrder($section->getAttribute('order')); } if ($section->hasAttribute('if-parameter')) { $route->setIfParameter($section->getAttribute('if-parameter')); } if ($section->hasAttribute('cache-ttl')) { $cache_ttl = $section->getAttribute('cache-ttl'); if (is_numeric($cache_ttl)) { $cache_ttl = (int) $cache_ttl; } $route->setCacheTtl($cache_ttl); } if ($section->hasAttribute('only-ssl')) { $only_ssl = __ConfigurationValueResolver::toBool($section->getAttribute('only-ssl')); $route->setOnlySSL($only_ssl); } if ($section->hasAttribute('redirect-to')) { $route_to_redirect_to = $section->getAttribute('redirect-to'); if ($section->hasAttribute('redirection-code')) { $redirection_code = $section->getAttribute('redirection-code'); } else { $redirection_code = 302; } $route->setRouteToRedirectTo($route_to_redirect_to, $redirection_code); } $url_regular_expression = $section->getAttribute('uri-pattern'); $route->setUrlPattern($url_regular_expression); $var_patterns = array(); preg_match_all('/\\$[_A-Za-z][_A-Za-z0-9]*/', $url_regular_expression, $var_order); foreach ($var_order[0] as $varpattern_name) { $varpattern_section = $section->getSection('variable', null, array('name' => $varpattern_name)); if ($varpattern_section != null) { $varpattern = $varpattern_section->getAttribute('var-pattern'); $var_patterns[$varpattern_name] = $varpattern; } } $route->setVariablePatterns($var_patterns); $sub_sections = $section->getSections(); foreach ($sub_sections as &$sub_section) { switch ($sub_section->getName()) { case 'parameter': $route->addFixedParameter($sub_section->getAttribute('name'), $sub_section->getAttribute('value')); break; case 'if-isset': $variable = $sub_section->getAttribute('variable'); $parameter_sections = $sub_section->getSections(); $parameters = array(); foreach ($parameter_sections as $parameter_section) { $parameters[$parameter_section->getAttribute('name')] = $parameter_section->getAttribute('value'); } $route->addIfIssetCondition($variable, $parameters); break; case 'if-equals': $variable = $sub_section->getAttribute('variable'); $value = $sub_section->getAttribute('value'); $parameter_sections = $sub_section->getSections(); $parameters = array(); foreach ($parameter_sections as $parameter_section) { $parameters[$parameter_section->getAttribute('name')] = $parameter_section->getAttribute('value'); } $route->addIfEqualsCondition($variable, $value, $parameters); break; case 'front-controller': $route->setFrontControllerClass($sub_section->getAttribute('class')); break; case 'flow': $route->setFlowId($sub_section->getAttribute('id')); break; case 'action': $action_identity = new __ActionIdentity(); if ($sub_section->hasAttribute('controller')) { $action_identity->setControllerCode($sub_section->getAttribute('controller')); } if ($sub_section->hasAttribute('code')) { $action_identity->setActionCode($sub_section->getAttribute('code')); } else { if ($sub_section->hasAttribute('action')) { $action_identity->setActionCode($sub_section->getAttribute('action')); } } $route->setActionIdentity($action_identity); break; } } //resolves route components before caching to avoid repeating this calculation on each request $route->resolveRouteComponents(); return $route; }
public function &_createModelServices(__ConfigurationSection &$section, $receiver_type, array $return_value) { if ($receiver_type == self::MODEL_RECEIVER_CLASS) { $receiver = $section->getAttribute('name'); } else { $receiver = $section->getAttribute('id'); } $subsections = $section->getSections(); foreach ($subsections as $service_section) { switch (strtoupper($service_section->getName())) { case 'SERVICE': $name = $service_section->getAttribute('name'); $class_method = $service_section->getAttribute('class-method'); $model_service_definition = new __ModelServiceDefinition($name); if ($receiver_type == self::MODEL_RECEIVER_CLASS) { $model_service_definition->setClass($receiver); } else { if ($receiver_type == self::MODEL_RECEIVER_INSTANCE) { $model_service_definition->setInstance($receiver); } } $model_service_definition->setService($class_method); if ($service_section->hasAttribute('cache')) { $model_service_definition->setCache(__ConfigurationValueResolver::toBool($service_section->getAttribute('cache'))); } if ($service_section->hasAttribute('cache-ttl')) { $model_service_definition->setCacheTtl($service_section->getAttribute('cache-ttl')); } if ($service_section->hasAttribute('remote')) { $model_service_definition->setRemote($service_section->getAttribute('remote')); } $service_subsections = $service_section->getSections(); foreach ($service_subsections as &$service_subsection) { switch (strtoupper($service_subsection->getName())) { case 'PERMISSION': $model_service_definition->setRequiredPermission($service_subsection->getAttribute('id')); break; case 'SERVICE-ARG': $model_service_argument = new __ModelServiceArgument(); if ($service_subsection->hasAttribute('name')) { $model_service_argument->setName($service_subsection->getAttribute('name')); } else { throw __ExceptionFactory::getInstance()->createException('Missing name attribute in model service argument definition: ' . $name); } if ($service_subsection->hasAttribute('index')) { $model_service_argument->setIndex($service_subsection->getAttribute('index')); } if ($service_subsection->hasAttribute('optional')) { $model_service_argument->setOptional(__ConfigurationValueResolver::toBool($service_subsection->getAttribute('optional'))); } $model_service_definition->addArgument($model_service_argument); unset($model_service_argument); break; } } if (key_exists($model_service_definition->getAlias(), $return_value)) { throw new __ConfigurationException('Duplicate definition of model service: ' . $model_service_definition->getAlias()); } else { $return_value[$model_service_definition->getAlias()] =& $model_service_definition; unset($model_service_definition); } break; } } return $return_value; }
private function &_getComponentPropertySpec(__ConfigurationSection $component_property_section) { $return_value = null; if ($component_property_section->hasAttribute('name')) { $property_name = $component_property_section->getAttribute('name'); if ($component_property_section->hasAttribute('target-member')) { $return_value = new __ComponentProperty2MemberSpec($property_name); $return_value->setMember($component_property_section->getAttribute('target-member')); } else { if ($component_property_section->hasAttribute('target-component')) { $return_value = new __ComponentProperty2ComponentSpec($property_name); $return_value->setComponent($component_property_section->getAttribute('target-component')); } } if ($return_value != null && $component_property_section->hasAttribute('target-property')) { $return_value->setProperty($component_property_section->getAttribute('target-property')); } } else { throw new __ConfigurationException('Missing property name in ui-component-interface section'); } return $return_value; }
private function _readConfigurationDirectives(__ConfigurationSection &$section) { $configuration_directives =& $section->getSections(); foreach ($configuration_directives as &$configuration_directive) { switch (strtoupper($configuration_directive->getName())) { case 'SECTION-HANDLER': $this->_processSectionHandler($configuration_directive); break; case 'AUTOLOAD': $this->_processAutoload($configuration_directive); break; } } }
protected function _getPlainTextContent(__ConfigurationSection &$section) { $value_content = $section->getProperty('#text'); if ($value_content == null) { $value_content = $section->getProperty('#cdata-section'); } if ($value_content != null) { $return_value = $value_content->getContent(); } else { $return_value = ''; } return $return_value; }
protected function _parseAttribute(__ConfigurationSection &$flow_section) { $attribute = new __FlowAttribute(); if ($flow_section->hasAttribute('attribute') && $flow_section->hasAttribute('scope')) { $flow_attribute = new __FlowAttribute(); $flow_attribute->setAttribute($flow_section->getAttribute('attribute')); $scope = __WebflowExpressionHelper::resolveScope($flow_section->getAttribute('scope')); $flow_attribute->setScope($scope); $attribute->setAttribute($flow_attribute); } if ($flow_section->hasAttribute('value')) { $value = __WebflowExpressionHelper::resolveExpression($flow_section->getAttribute('value')); $attribute->setValue($value); } return $attribute; }