protected function addServices(SimpleXMLElement $xml, Config $config) { foreach ($config->getServices() as $service) { if (!$xml->xpath("//config:services/config:service[@id='{$service->getId()}']")) { $element = $xml->services->addChild("service"); $element->addAttribute("id", $service->getId()); $element->addAttribute("class", $service->getClass()); if ($service->getScope()) { $element->addAttribute("scope", $service->getScope()); } foreach ($service->getArguments() as $argument) { $serviceXml = $element->addChild("argument"); if (null !== $argument->getId()) { $serviceXml->addAttribute("id", $argument->getId()); } if (null !== $argument->getType() && Argument::TYPE_STRING !== $argument->getType()) { $serviceXml->addAttribute("type", $argument->getType()); } if (null !== $argument->getValue()) { $serviceXml[0] = $argument->getValue(); } } foreach ($service->getTags() as $tag) { $tagXml = $element->addChild("tag"); foreach ($tag->getParameters() as $name => $parameter) { $tagXml->addAttribute($name, $parameter); } } } } }
protected function parseServices(SimpleXMLElement $xml, Config $config) { /** @var SimpleXmlElement $serviceXml */ foreach ($xml->xpath("//config:services/config:service") as $serviceXml) { $this->parseService($serviceXml, $config); } }
protected function readBehaviors(SimpleXMLElement $xml, Table $table) { /** * @var SimpleXmlElement $behavior * * report behaviors */ foreach ($xml->xpath(".//behavior") as $behavior) { $table->addBehavior($name = $behavior->getAttributeAsPhp('name')); if ($name === 'i18n') { foreach ($behavior->xpath(".//parameter") as $parameter) { if ($parameter->getAttributeAsPhp('name') === 'i18n_columns') { $i18nColumns = array_map("trim", explode(",", $parameter->getAttributeAsPhp("value"))); foreach ($i18nColumns as $i18nColumn) { $table->getColumn($i18nColumn)->setI18n(true); } } } } } }
/** * Processes anonymous services * * @param SimpleXMLElement $xml * @param string $file * * @return array An array of anonymous services */ private function processAnonymousServices(SimpleXMLElement $xml, $file) { $definitions = array(); $count = 0; // anonymous services as arguments if (false === ($nodes = $xml->xpath('//container:argument[@type="service"][not(@id)]'))) { return $xml; } foreach ($nodes as $node) { // give it a unique name $node['id'] = sprintf('%s_%d', md5($file), ++$count); $definitions[(string) $node['id']] = array($node->service, $file, false); $node->service['id'] = (string) $node['id']; } // anonymous services "in the wild" if (false === ($nodes = $xml->xpath('//container:services/container:service[not(@id)]'))) { return $xml; } foreach ($nodes as $node) { // give it a unique name $node['id'] = sprintf('%s_%d', md5($file), ++$count); $definitions[(string) $node['id']] = array($node, $file, true); $node->service['id'] = (string) $node['id']; } // resolve definitions krsort($definitions); foreach ($definitions as $id => $def) { // anonymous services are always private $def[0]['public'] = false; $this->parseDefinition($id, $def[0], $def[1]); $oNode = dom_import_simplexml($def[0]); if (true === $def[2]) { $nNode = new \DOMElement('_services'); $oNode->parentNode->replaceChild($nNode, $oNode); $nNode->setAttribute('id', $id); } else { $oNode->parentNode->removeChild($oNode); } } return $xml; }
protected function parseImports(SimpleXMLElement $xml) { if (false === ($imports = $xml->xpath('//config:imports/config:import'))) { return; } $con = Propel::getWriteConnection(ImportTableMap::DATABASE_NAME); $con->beginTransaction(); try { /** @var SimpleXMLElement $import */ foreach ($imports as $import) { $id = (string) $import->getAttributeAsPhp("id"); $class = (string) $import->getAttributeAsPhp("class"); $categoryRef = (string) $import->getAttributeAsPhp("category_id"); if (!class_exists($class)) { throw new \ErrorException("The class \"{$class}\" doesn't exist"); } $category = ImportCategoryQuery::create()->findOneByRef($categoryRef); if (null === $category) { throw new \ErrorException("The import category \"{$categoryRef}\" doesn't exist"); } $importModel = ImportQuery::create()->findOneByRef($id); if (null === $importModel) { $importModel = new Import(); $importModel->setRef($id); } $importModel->setImportCategory($category)->setHandleClass($class)->save($con); /** @var SimpleXMLElement $descriptive */ foreach ($import->children() as $descriptive) { $locale = $descriptive->getAttributeAsPhp("locale"); $title = null; $description = null; /** @var SimpleXMLElement $row */ foreach ($descriptive->children() as $row) { switch ($row->getName()) { case "title": $title = (string) $row; break; case "description": $description = (string) $row; break; } } $importModel->setLocale($locale)->setTitle($title)->setDescription($description)->save($con); } } $con->commit(); } catch (\Exception $e) { $con->rollBack(); Tlog::getInstance()->error($e->getMessage()); } }
protected function processAnonymousServices(SimpleXMLElement $xml, $file) { $definitions = array(); $count = 0; // find anonymous service definitions $xml->registerXPathNamespace('container', 'http://www.symfony-project.org/schema/dic/services'); // anonymous services as arguments $nodes = $xml->xpath('//container:argument[@type="service"][not(@id)]'); foreach ($nodes as $node) { // give it a unique name $node['id'] = sprintf('%s_%d', md5($file), ++$count); $definitions[(string) $node['id']] = array($node->service, $file, false); $node->service['id'] = (string) $node['id']; } // anonymous services "in the wild" $nodes = $xml->xpath('//container:service[not(@id)]'); foreach ($nodes as $node) { // give it a unique name $node['id'] = sprintf('%s_%d', md5($file), ++$count); $definitions[(string) $node['id']] = array($node, $file, true); $node->service['id'] = (string) $node['id']; } // resolve definitions krsort($definitions); foreach ($definitions as $id => $def) { $this->parseDefinition($id, $def[0], $def[1]); $oNode = dom_import_simplexml($def[0]); if (true === $def[2]) { $nNode = new \DOMElement('_services'); $oNode->parentNode->replaceChild($nNode, $oNode); $nNode->setAttribute('id', $id); } else { $oNode->parentNode->removeChild($oNode); } } return $xml; }
/** * Parse one extend-customergroupacl * * @param SimpleXMLElement $extendCustomerGroupAcl * @param CustomerGroup $customerGroupModel * @param SimpleXMLElement $xml The global xml for retreive the parent * @throws \Exception * @throws \Propel\Runtime\Exception\PropelException */ protected function parseExtendCustomerGroupAcl(SimpleXMLElement $extendCustomerGroupAcl, CustomerGroup $customerGroupModel, SimpleXMLElement $xml) { $extendCustomerGroupCode = $extendCustomerGroupAcl->getAttributeAsPhp('group'); //If an aclcode is specified in extends $aclcode = $extendCustomerGroupAcl->getAttributeAsPhp('aclcode'); if ($aclcode !== null && $aclcode !== '') { $extendCustomerGroupAcls = $xml->xpath('//config:customergroups' . '/config:customergroup[@group="' . $extendCustomerGroupCode . '"]' . '/config:customergroupacl[@aclcode="' . $aclcode . '"]'); //Parse acls who match to customergroup and aclcode given in extends /** @var SimpleXMLElement $extendCustomerGroupAcl */ foreach ($extendCustomerGroupAcls as $extendCustomerGroupAcl) { $this->parseCustomerGroupAcl($extendCustomerGroupAcl, $customerGroupModel); } //Don't add the other acl return; } //Get the customerGroups who matches to the 'group' attribute given in extends-customergroupacl node $extendCustomerGroups = $xml->xpath('//config:customergroups' . '/config:customergroup[@group="' . $extendCustomerGroupCode . '"]'); /** @var SimpleXMLElement $extendsCustomerGroup */ foreach ($extendCustomerGroups as $extendCustomerGroup) { /** @var SimpleXMLElement $extendCustomerGroupChild */ foreach ($extendCustomerGroup->children() as $extendCustomerGroupChild) { switch ($extendCustomerGroupChild->getName()) { case 'extends-customergroupacl': $this->parseExtendCustomerGroupAcl($extendCustomerGroupChild, $customerGroupModel, $xml); break; case 'customergroupacl': $this->parseCustomerGroupAcl($extendCustomerGroupChild, $customerGroupModel); break; default: break; } } } }