/** * Returns a scalar representation of actual value, * Returns $other if internal acutal value is not set * * @param Varien_Simplexml_Element $other * @return scalar */ protected function getActualValue($other = null) { if (!$this->_useActualValue && $other->hasChildren()) { return $this->getXmlAsDom($other); } elseif (!$this->_useActualValue) { return (string) $other; } return parent::getActualValue($other); }
/** * Extends one node * * @param Varien_Simplexml_Element $source * @param boolean $overwrite * * @return Varien_Simplexml_Element * @access public */ public function extendChild($source, $overwrite = false) { // this will be our new target node $targetChild = null; // name of the source node $sourceName = $source->getName(); // here we have children of our source node $sourceChildren = $source->children(); if (!$source->hasChildren()) { // handle string node if (isset($this->{$sourceName})) { // if target already has children return without regard if ($this->{$sourceName}->children()) { return $this; } if ($overwrite) { if (Mage::registry('conflict_datastore_enabled')) { $factory = new Bronto_Verify_Model_Path_Locator_Factory(); $locator = $factory->getLocator(); $dataStore = Mage::registry('conflict_datastore'); $dataStore->addRewrite((string) $this->{$sourceName}, (string) $source, Mage::registry('conflict_datastore_config_file'), $locator->getPath($source)); } unset($this->{$sourceName}); } else { return $this; } } $targetChild = $this->addChild($sourceName, $source->xmlentities()); $targetChild->setParent($this); foreach ($source->attributes() as $key => $value) { $targetChild->addAttribute($key, $this->xmlentities($value)); } return $this; } if (isset($this->{$sourceName})) { $targetChild = $this->{$sourceName}; } if (is_null($targetChild)) { // if child target is not found create new and descend $targetChild = $this->addChild($sourceName); $targetChild->setParent($this); foreach ($source->attributes() as $key => $value) { $targetChild->addAttribute($key, $this->xmlentities($value)); } } // finally add our source node children to resulting new target node foreach ($sourceChildren as $childNode) { $targetChild->extendChild($childNode, $overwrite); } return $this; }
/** * translate node * * @access protected * @param Varien_Simplexml_Element $node * @return Ultimate_ModuleCreator_Model_Config * @author Marius Strajeru <*****@*****.**> */ protected function _translateNode(&$node) { if ($node->getAttribute('translate')) { $fields = explode(' ', $node->getAttribute('translate')); $module = $node->getAttribute('module') ? (string) $node->getAttribute('module') : $this->_getDefaultTranslateModule(); foreach ($fields as $field) { if ($node->{$field}) { $node->{$field} = Mage::helper($module)->__((string) $node->{$field}); } } } if ($node->hasChildren()) { foreach ($node->children() as $child) { $this->_translateNode($child); } } return $this; }
/** * Process config value * * @param string $fullPath * @param string $path * @param Varien_Simplexml_Element $node * @return string */ protected function _processConfigValue($fullPath, $path, $node) { if (isset($this->_configCache[$path])) { return $this->_configCache[$path]; } if ($node->hasChildren()) { $aValue = array(); foreach ($node->children() as $k => $v) { $aValue[$k] = $this->_processConfigValue($fullPath . '/' . $k, $path . '/' . $k, $v); } $this->_configCache[$path] = $aValue; return $aValue; } $sValue = (string) $node; if (!empty($node['backend_model']) && !empty($sValue)) { $backend = Mage::getModel((string) $node['backend_model']); $backend->setPath($path)->setValue($sValue)->afterLoad(); $sValue = $backend->getValue(); } if (is_string($sValue) && strpos($sValue, '{{') !== false) { if (strpos($sValue, '{{unsecure_base_url}}') !== false) { $unsecureBaseUrl = $this->getConfig(self::XML_PATH_UNSECURE_BASE_URL); $sValue = str_replace('{{unsecure_base_url}}', $unsecureBaseUrl, $sValue); } elseif (strpos($sValue, '{{secure_base_url}}') !== false) { $secureBaseUrl = $this->getConfig(self::XML_PATH_SECURE_BASE_URL); $sValue = str_replace('{{secure_base_url}}', $secureBaseUrl, $sValue); } elseif (strpos($sValue, '{{base_url}}') === false) { $sValue = Mage::getConfig()->substDistroServerVars($sValue); } } $this->_configCache[$path] = $sValue; return $sValue; }
/** * Convert xml to array * * @param Varien_Simplexml_Element $element XML element * @return array|string */ protected function _xmlToArray(Varien_Simplexml_Element $element) { if (!$element->hasChildren()) { return (string) $element; } $result = array(); foreach ($element->children() as $_name => $_child) { if (isset($result[$_name])) { if (!is_array($result[$_name]) || !isset($result[$_name]['__list'])) { $result[$_name] = array($result[$_name]); $result[$_name]['__list'] = true; } $result[$_name][] = $this->_xmlToArray($_child); } else { $result[$_name] = $this->_xmlToArray($_child); } } // Remove temp __list mark array_walk($result, function (&$node) { if (is_array($node)) { unset($node['__list']); } }); return $result; }
/** * Checks multiple values nodes. * Values are comma separated string * * @param Varien_Simplexml_Element $other * @throws RuntimeException * @return boolean */ protected function evaluateContainValues($other) { if ($other->hasChildren()) { throw new RuntimeException(sprintf('Config node "%s" is not a string of comma separated values, passed expected value: %s', $this->_nodePath, self::getExporter()->export($this->_expectedValue))); } $values = explode(',', (string) $other); if (in_array($this->_expectedValue, $values)) { return true; } return false; }
/** * Extends one node * * @param Varien_Simplexml_Element $source * @param boolean $overwrite * @return Varien_Simplexml_Element */ public function extendChild($source, $overwrite = false) { // this will be our new target node $targetChild = null; // name of the source node $sourceName = $source->getName(); // here we have children of our source node $sourceChildren = $source->children(); if (!$source->hasChildren()) { // handle string node if (isset($this->{$sourceName})) { // if target already has children return without regard if ($this->{$sourceName}->hasChildren()) { return $this; } if ($overwrite) { unset($this->{$sourceName}); } else { return $this; } } $targetChild = $this->addChild($sourceName, $source->xmlentities()); $targetChild->setParent($this); foreach ($source->attributes() as $key => $value) { $targetChild->addAttribute($key, $this->xmlentities($value)); } return $this; } if (isset($this->{$sourceName})) { $targetChild = $this->{$sourceName}; } if (is_null($targetChild)) { // if child target is not found create new and descend $targetChild = $this->addChild($sourceName); $targetChild->setParent($this); foreach ($source->attributes() as $key => $value) { $targetChild->addAttribute($key, $this->xmlentities($value)); } } // finally add our source node children to resulting new target node foreach ($sourceChildren as $childKey => $childNode) { $targetChild->extendChild($childNode, $overwrite); } return $this; }
/** * Process config value * * @param string $fullPath * @param string $path * @param Varien_Simplexml_Element $node * @return string */ protected function _processConfigValue($fullPath, $path, $node) { if (isset($this->_configCache[$path])) { return $this->_configCache[$path]; } if ($node->hasChildren()) { $aValue = array(); foreach ($node->children() as $k => $v) { $aValue[$k] = $this->_processConfigValue($fullPath . '/' . $k, $path . '/' . $k, $v); } $this->_configCache[$path] = $aValue; return $aValue; } $sValue = (string) $node; if (!empty($node['backend_model']) && !empty($sValue)) { $backend = Mage::getModel((string) $node['backend_model']); $backend->setPath($path)->setValue($sValue)->afterLoad(); $sValue = $backend->getValue(); } if (is_string($sValue) && preg_match('/{{(.*)}}.*/', $sValue, $matches)) { $placeholder = $matches[1]; $url = false; if ($placeholder == 'unsecure_base_url' || $placeholder == 'unsecure_public_url') { $url = $this->getConfig(self::XML_PATH_UNSECURE_BASE_URL); } elseif ($placeholder == 'secure_base_url' || $placeholder == 'secure_public_url') { $url = $this->getConfig(self::XML_PATH_SECURE_BASE_URL); } if ($placeholder == 'unsecure_public_url' || $placeholder == 'secure_public_url') { $pubName = Mage_Core_Model_Config_Options::PUB_DIRECTORY; $url .= substr(dirname($_SERVER['SCRIPT_FILENAME']), -4) == '/' . $pubName ? '' : $pubName . '/'; } if ($url) { $sValue = str_replace('{{' . $placeholder . '}}', $url, $sValue); } elseif (strpos($sValue, '{{base_url}}') !== false) { $sValue = Mage::getConfig()->substDistroServerVars($sValue); } } $this->_configCache[$path] = $sValue; return $sValue; }
/** * Checks multiple values nodes. * Values are comma separated string * * @param Varien_Simplexml_Element $other * @return boolean */ protected function evaluateContainValue($other) { if ($other->hasChildren()) { throw new RuntimeException(sprintf('Config node "%s" is not a string of comma separated values, passed expected value: %s', $this->_nodePath, PHPUnit_Util_Type::toString($this->_expectedValue))); } $values = explode(',', (string) $other); if (!in_array($this->_expectedValue, $values)) { return true; } return false; }