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; }
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; }
private function &_createRole(__ConfigurationSection &$role_section) { $role_id = strtoupper($role_section->getAttribute('id')); if (key_exists($role_id, $this->_role_ids)) { throw new __ConfigurationException('Double declaration of role ' . $permission_id . '. If your intention was to reference an already existing role, use a REF tag instead of ROLE'); } else { $this->_role_ids[$role_id] = true; } $role = new __Role($role_id); $subsections = $role_section->getSections(); foreach ($subsections as $subsection) { switch (strtoupper($subsection->getName())) { case 'JUNIOR-ROLES': $this->_setJuniorRoles($role, $subsection); break; case 'PERMISSIONS': $this->_setPermissions($role, $subsection); break; } } return $role; }
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 _parseValueNode(__ConfigurationSection $node_value, $property_name, $instance_id) { $return_value = null; if ($node_value->getName() == 'ref') { if ($node_value->hasAttribute('id')) { $return_value = new __InstanceReference(); $return_value->setReferenceId($node_value->getAttribute('id')); } } else { if ($node_value->getName() == 'context-instance') { $return_value = $this->_createInstanceDefinition($node_value); $this->_addInstanceDefinition($return_value); } else { if ($node_value->getName() == 'list') { $return_value = array(); $value_nodes = $node_value->getSections(); foreach ($value_nodes as $value_node) { $key = null; if ($value_node->getName() == 'entry') { if ($value_node->hasAttribute('key')) { $key = $value_node->getAttribute('key'); } $value_section = $value_node->getSections(); if (count($value_section) == 1) { $value_node = current($value_section); } else { throw new __ConfigurationException("Wrong entry content for property " . $property_name . " on instance " . $instance_id); } } $value = $this->_parseValueNode($value_node, $property_name, $instance_id); if ($key !== null) { $return_value[$key] = $value; } else { $return_value[] = $value; } } } else { if ($node_value->getName() == 'value') { $return_value = $this->_getPlainTextContent($node_value); } else { if ($node_value->getName() == 'null') { $return_value = null; } } } } } 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; }