Beispiel #1
0
 protected function parseService(SimpleXMLElement $serviceXml, Config $config)
 {
     $service = new Service($serviceXml->getAttributeAsPhp("id"), $serviceXml->getAttributeAsPhp("class"), $serviceXml->getAttributeAsPhp("scope"));
     static::registerNamespace($serviceXml);
     foreach ($serviceXml->xpath(".//config:tag") as $tagXml) {
         $parameters = array();
         foreach ($tagXml->attributes() as $k => $v) {
             $parameters[$k] = $v;
         }
         $service->addTag(new Tag($parameters["name"], $parameters));
     }
     $config->addService($service);
 }
 /**
  * Parses an individual Definition
  *
  * @param string           $id
  * @param SimpleXMLElement $service
  * @param string           $file
  *
  * @return void
  */
 private function parseDefinition($id, $service, $file)
 {
     if ((string) $service['alias']) {
         $public = true;
         if (isset($service['public'])) {
             $public = $service->getAttributeAsPhp('public');
         }
         $this->container->setAlias($id, new Alias((string) $service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator((string) $service['parent']);
     } else {
         $definition = new Definition();
     }
     foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'abstract') as $key) {
         if (isset($service[$key])) {
             $method = 'set' . str_replace('-', '', $key);
             $definition->{$method}((string) $service->getAttributeAsPhp($key));
         }
     }
     if ($service->file) {
         $definition->setFile((string) $service->file);
     }
     $definition->setArguments($service->getArgumentsAsPhp('argument'));
     $definition->setProperties($service->getArgumentsAsPhp('property'));
     if (isset($service->configurator)) {
         if (isset($service->configurator['function'])) {
             $definition->setConfigurator((string) $service->configurator['function']);
         } else {
             if (isset($service->configurator['service'])) {
                 $class = new Reference((string) $service->configurator['service'], ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = (string) $service->configurator['class'];
             }
             $definition->setConfigurator(array($class, (string) $service->configurator['method']));
         }
     }
     foreach ($service->call as $call) {
         $definition->addMethodCall((string) $call['method'], $call->getArgumentsAsPhp('argument'));
     }
     foreach ($service->tag as $tag) {
         $parameters = array();
         foreach ($tag->attributes() as $name => $value) {
             if ('name' === $name) {
                 continue;
             }
             $parameters[$name] = SimpleXMLElement::phpize($value);
         }
         $definition->addTag((string) $tag['name'], $parameters);
     }
     $this->container->setDefinition($id, $definition);
 }
 /**
  * Parses an individual Definition.
  *
  * @param string           $id
  * @param SimpleXMLElement $service
  * @param string           $file
  */
 private function parseDefinition($id, $service, $file)
 {
     if ((string) $service['alias']) {
         $public = true;
         if (isset($service['public'])) {
             $public = $service->getAttributeAsPhp('public');
         }
         $this->container->setAlias($id, new Alias((string) $service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator((string) $service['parent']);
     } else {
         $definition = new Definition();
     }
     foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'synchronized', 'lazy', 'abstract') as $key) {
         if (isset($service[$key])) {
             $method = 'set' . str_replace('-', '', $key);
             $definition->{$method}((string) $service->getAttributeAsPhp($key));
         }
     }
     if ($service->file) {
         $definition->setFile((string) $service->file);
     }
     $definition->setArguments($service->getArgumentsAsPhp('argument'));
     $definition->setProperties($service->getArgumentsAsPhp('property'));
     if (isset($service->configurator)) {
         if (isset($service->configurator['function'])) {
             $definition->setConfigurator((string) $service->configurator['function']);
         } else {
             if (isset($service->configurator['service'])) {
                 $class = new Reference((string) $service->configurator['service'], ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = (string) $service->configurator['class'];
             }
             $definition->setConfigurator(array($class, (string) $service->configurator['method']));
         }
     }
     foreach ($service->call as $call) {
         $definition->addMethodCall((string) $call['method'], $call->getArgumentsAsPhp('argument'));
     }
     foreach ($service->tag as $tag) {
         $parameters = array();
         foreach ($tag->attributes() as $name => $value) {
             if ('name' === $name) {
                 continue;
             }
             if (false !== strpos($name, '-') && false === strpos($name, '_') && !array_key_exists($normalizedName = str_replace('-', '_', $name), $parameters)) {
                 $parameters[$normalizedName] = SimpleXMLElement::phpize($value);
             }
             // keep not normalized key for BC too
             $parameters[$name] = SimpleXMLElement::phpize($value);
         }
         if ('' === (string) $tag['name']) {
             throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
         }
         $definition->addTag((string) $tag['name'], $parameters);
     }
     $this->container->setDefinition($id, $definition);
 }
 /**
  * Parse one customergroupacl
  *
  * @param SimpleXMLElement $customerGroupAcl A customergroupacl
  * @param CustomerGroup $customerGroupModel CustomerGroup propel object for who the access have to be created
  *
  * @throws \Exception When an error is detected on xml file (customer group or acl don't exist)
  */
 protected function parseCustomerGroupAcl(SimpleXMLElement $customerGroupAcl, CustomerGroup $customerGroupModel)
 {
     $acl = AclQuery::create()->findOneByCode($customerGroupAcl->getAttributeAsPhp('aclcode'));
     if (null === $customerGroupModel) {
         throw new \Exception($this->translator->trans("Error in %a file the customer group '%s' doesn't exist", ['%a' => $this->xmlFilePath, '%s' => $customerGroupModel->getCode()], CustomerGroupAcl::DOMAIN_MESSAGE));
     }
     if (null === $acl) {
         throw new \Exception($this->translator->trans("Error in %a file the acl '%s' doesn't exist", ['%a' => $this->xmlFilePath, '%s' => $customerGroupAcl->getAttributeAsPhp('aclcode')], CustomerGroupAcl::DOMAIN_MESSAGE));
     }
     $this->parseAccesses($customerGroupAcl->children(), $acl, $customerGroupModel);
 }