Varien_Simplexml_Config Class Reference

Inheritance diagram for Varien_Simplexml_Config:

Mage_Admin_Model_Config Mage_Adminhtml_Model_Config Mage_Api_Model_Config Mage_Api_Model_Wsdl_Config_Base Mage_Core_Model_Config_Base Mage_Core_Model_Layout Mage_Install_Model_Config Mage_Api_Model_Wsdl_Config Mage_Core_Model_Config Mage_Core_Model_Config_System Mage_Customer_Model_Address_Config Mage_Sales_Model_Order_Config Mage_Sales_Model_Order_Creditmemo_Config Mage_Sales_Model_Order_Invoice_Config

List of all members.

Public Member Functions

 __construct ($sourceData=null)
 setXml (Varien_Simplexml_Element $node)
 getNode ($path=null)
 getXpath ($xpath)
 setCache ($cache)
 getCache ()
 setCacheSaved ($flag)
 getCacheSaved ()
 setCacheId ($id)
 getCacheId ()
 setCacheTags ($tags)
 getCacheTags ()
 setCacheLifetime ($lifetime)
 getCacheLifetime ()
 setCacheChecksum ($data)
 updateCacheChecksum ($data)
 getCacheChecksum ()
 getCacheChecksumId ()
 fetchCacheChecksum ()
 validateCacheChecksum ()
 loadCache ()
 saveCache ($tags=null)
 getXmlString ()
 removeCache ()
 loadFile ($filePath)
 loadString ($string)
 loadDom ($dom)
 setNode ($path, $value, $overwrite=true)
 applyExtends ()
 processFileData ($text)
 extend (Varien_Simplexml_Config $config, $overwrite=true)

Protected Member Functions

 _loadCache ($id)
 _saveCache ($data, $id, $tags=array(), $lifetime=false)
 _removeCache ($id)

Protected Attributes

 $_xml = null
 $_cacheId = null
 $_cacheTags = array()
 $_cacheLifetime = null
 $_cacheChecksum = false
 $_cacheSaved = false
 $_cache = null
 $_elementClass = 'Varien_Simplexml_Element'
 $_xpathExtends = "//*[@extends]"


Detailed Description

Definition at line 35 of file Config.php.


Constructor & Destructor Documentation

__construct ( sourceData = null  ) 

Constructor

Initializes XML for this configuration

See also:
self.setXml
Parameters:
string|Varien_Simplexml_Element $sourceData
string $sourceType

Reimplemented in Mage_Api_Model_Config, Mage_Api_Model_Wsdl_Config_Base, Mage_Api_Model_Wsdl_Config, Mage_Core_Model_Config_Base, Mage_Core_Model_Config_System, Mage_Core_Model_Config, and Mage_Core_Model_Layout.

Definition at line 110 of file Config.php.

00110                                                   {
00111         if (is_null($sourceData)) {
00112             return;
00113         }
00114         if ($sourceData instanceof Varien_Simplexml_Element) {
00115            $this->setXml($sourceData);
00116         } elseif (is_string($sourceData) && !empty($sourceData)) {
00117             if (strlen($sourceData)<1000 && is_readable($sourceData)) {
00118                 $this->loadFile($sourceData);
00119             } else {
00120                 $this->loadString($sourceData);
00121             }
00122         }
00123         #$this->setCache(new Varien_Simplexml_Config_Cache_File());
00124         #$this->getCache()->setConfig($this);
00125     }


Member Function Documentation

_loadCache ( id  )  [protected]

Enter description here...

Parameters:
string $id
Returns:
boolean

Reimplemented in Mage_Api_Model_Config, Mage_Api_Model_Wsdl_Config, and Mage_Core_Model_Config.

Definition at line 452 of file Config.php.

00453     {
00454         return $this->getCache()->load($id);
00455     }

_removeCache ( id  )  [protected]

Enter description here...

Todo:
check this, as there are no caches that implement remove() method
Parameters:
string $id
Returns:
unknown

Reimplemented in Mage_Api_Model_Config, Mage_Api_Model_Wsdl_Config, and Mage_Core_Model_Config.

Definition at line 478 of file Config.php.

00479     {
00480         return $this->getCache()->remove($id);
00481     }

_saveCache ( data,
id,
tags = array(),
lifetime = false 
) [protected]

Enter description here...

Parameters:
string $data
string $id
array $tags
int|boolean $lifetime
Returns:
boolean

Reimplemented in Mage_Api_Model_Config, Mage_Api_Model_Wsdl_Config, and Mage_Core_Model_Config.

Definition at line 466 of file Config.php.

00467     {
00468         return $this->getCache()->save($data, $id, $tags, $lifetime);
00469     }

applyExtends (  ) 

Process configuration xml

Returns:
Varien_Simplexml_Config

Definition at line 561 of file Config.php.

00562     {
00563         $targets = $this->getXpath($this->_xpathExtends);
00564         if (!$targets) {
00565             return $this;
00566         }
00567 
00568         foreach ($targets as $target) {
00569             $sources = $this->getXpath((string)$target['extends']);
00570             if ($sources) {
00571                 foreach ($sources as $source) {
00572                     $target->extend($source);
00573                 }
00574             } else {
00575                 #echo "Not found extend: ".(string)$target['extends'];
00576             }
00577             #unset($target['extends']);
00578         }
00579         return $this;
00580     }

extend ( Varien_Simplexml_Config config,
overwrite = true 
)

Enter description here...

Parameters:
Varien_Simplexml_Config $config
boolean $overwrite
Returns:
Varien_Simplexml_Config

Definition at line 600 of file Config.php.

00601     {
00602         $this->getNode()->extend($config->getNode(), $overwrite);
00603         return $this;
00604     }

fetchCacheChecksum (  ) 

Enter description here...

Returns:
boolean

Definition at line 348 of file Config.php.

00349     {
00350         return false;
00351     }

getCache (  ) 

Enter description here...

Returns:
Varien_Simplexml_Config_Cache_Abstract

Reimplemented in Mage_Api_Model_Config, Mage_Api_Model_Wsdl_Config, and Mage_Core_Model_Config.

Definition at line 193 of file Config.php.

00194     {
00195         return $this->_cache;
00196     }

getCacheChecksum (  ) 

Enter description here...

Returns:
string

Definition at line 328 of file Config.php.

00329     {
00330         return $this->_cacheChecksum;
00331     }

getCacheChecksumId (  ) 

Enter description here...

Returns:
string

Definition at line 338 of file Config.php.

00339     {
00340         return $this->getCacheId().'__CHECKSUM';
00341     }

getCacheId (  ) 

Enter description here...

Returns:
string

Definition at line 237 of file Config.php.

00238     {
00239         return $this->_cacheId;
00240     }

getCacheLifetime (  ) 

Enter description here...

Returns:
int

Definition at line 281 of file Config.php.

00282     {
00283         return $this->_cacheLifetime;
00284     }

getCacheSaved (  ) 

Enter description here...

Returns:
boolean

Definition at line 215 of file Config.php.

00216     {
00217         return $this->_cacheSaved;
00218     }

getCacheTags (  ) 

Enter description here...

Returns:
array

Definition at line 259 of file Config.php.

00260     {
00261         return $this->_cacheTags;
00262     }

getNode ( path = null  ) 

Returns node found by the $path

See also:
Varien_Simplexml_Element.descend
Parameters:
string $path
Returns:
Varien_Simplexml_Element

Definition at line 146 of file Config.php.

00147     {
00148         if (!$this->_xml instanceof Varien_Simplexml_Element) {
00149             return false;
00150         } elseif ($path === null) {
00151             return $this->_xml;
00152         } else {
00153             return $this->_xml->descend($path);
00154         }
00155     }

getXmlString (  ) 

Return Xml of node as string

Returns:
string

Reimplemented in Mage_Api_Model_Wsdl_Config.

Definition at line 429 of file Config.php.

00430     {
00431         return $this->getNode()->asNiceXml('', false);
00432     }

getXpath ( xpath  ) 

Returns nodes found by xpath expression

Parameters:
string $xpath
Returns:
array

Definition at line 163 of file Config.php.

00164     {
00165         if (empty($this->_xml)) {
00166             return false;
00167         }
00168 
00169         if (!$result = @$this->_xml->xpath($xpath)) {
00170             return false;
00171         }
00172 
00173         return $result;
00174     }

loadCache (  ) 

Enter description here...

Returns:
boolean

Definition at line 376 of file Config.php.

00377     {
00378         if (!$this->validateCacheChecksum()) {
00379             return false;
00380         }
00381 
00382         $xmlString = $this->_loadCache($this->getCacheId());
00383         $xml = simplexml_load_string($xmlString, $this->_elementClass);
00384         if ($xml) {
00385             $this->_xml = $xml;
00386             $this->setCacheSaved(true);
00387             return true;
00388         }
00389 
00390         return false;
00391     }

loadDom ( dom  ) 

Imports DOM node

Parameters:
DOMNode $dom
Returns:
Varien_Simplexml_Element

Definition at line 530 of file Config.php.

00531     {
00532         $xml = simplexml_import_dom($dom, $this->_elementClass);
00533 
00534         if ($xml) {
00535             $this->_xml = $xml;
00536             return true;
00537         }
00538 
00539         return false;
00540     }

loadFile ( filePath  ) 

Imports XML file

Parameters:
string $filePath
Returns:
Varien_Simplexml_Element

Reimplemented in Mage_Api_Model_Wsdl_Config_Base.

Definition at line 489 of file Config.php.

00490     {
00491         if (!is_readable($filePath)) {
00492             //throw new Exception('Can not read xml file '.$filePath);
00493             return false;
00494         }
00495 
00496         $fileData = file_get_contents($filePath);
00497         $fileData = $this->processFileData($fileData);
00498         return $this->loadString($fileData, $this->_elementClass);
00499     }

loadString ( string  ) 

Imports XML string

Parameters:
string $string
Returns:
Varien_Simplexml_Element

Definition at line 507 of file Config.php.

00508     {
00509         if (!empty($string)) {
00510             $xml = simplexml_load_string($string, $this->_elementClass);
00511         }
00512         else {
00513             throw new Exception('"$string" parameter for simplexml_load_string is empty');
00514         }
00515 
00516         if ($xml instanceof Varien_Simplexml_Element) {
00517             $this->_xml = $xml;
00518             return true;
00519         }
00520 
00521         return false;
00522     }

processFileData ( text  ) 

Stub method for processing file data right after loading the file text

Parameters:
string $text
Returns:
string

Reimplemented in Mage_Api_Model_Wsdl_Config_Base.

Definition at line 588 of file Config.php.

00589     {
00590         return $text;
00591     }

removeCache (  ) 

Enter description here...

Returns:
Varien_Simplexml_Config

Reimplemented in Mage_Core_Model_Config.

Definition at line 439 of file Config.php.

00440     {
00441         $this->_removeCache($this->getCacheId());
00442         $this->_removeCache($this->getCacheChecksumId());
00443         return $this;
00444     }

saveCache ( tags = null  ) 

Enter description here...

Parameters:
array $tags
Returns:
Varien_Simplexml_Config

Reimplemented in Mage_Core_Model_Config.

Definition at line 399 of file Config.php.

00400     {
00401         if ($this->getCacheSaved()) {
00402             return $this;
00403         }
00404         if (false===$this->getCacheChecksum()) {
00405             return $this;
00406         }
00407 
00408         if (is_null($tags)) {
00409             $tags = $this->_cacheTags;
00410         }
00411 
00412         if (!is_null($this->getCacheChecksum())) {
00413             $this->_saveCache($this->getCacheChecksum(), $this->getCacheChecksumId(), $tags, $this->getCacheLifetime());
00414         }
00415 
00416         $xmlString = $this->getXmlString();
00417         $this->_saveCache($xmlString, $this->getCacheId(), $tags, $this->getCacheLifetime());
00418 
00419         $this->setCacheSaved(true);
00420 
00421         return $this;
00422     }

setCache ( cache  ) 

Enter description here...

Parameters:
Varien_Simplexml_Config_Cache_Abstract $cache
Returns:
Varien_Simplexml_Config

Definition at line 182 of file Config.php.

00183     {
00184         $this->_cache = $cache;
00185         return $this;
00186     }

setCacheChecksum ( data  ) 

Enter description here...

Parameters:
string $data
Returns:
Varien_Simplexml_Config

Definition at line 292 of file Config.php.

00293     {
00294         if (is_null($data)) {
00295             $this->_cacheChecksum = null;
00296         } elseif (false===$data || 0===$data) {
00297             $this->_cacheChecksum = false;
00298         } else {
00299             $this->_cacheChecksum = md5($data);
00300         }
00301         return $this;
00302     }

setCacheId ( id  ) 

Enter description here...

Parameters:
string $id
Returns:
Varien_Simplexml_Config

Definition at line 226 of file Config.php.

00227     {
00228         $this->_cacheId = $id;
00229         return $this;
00230     }

setCacheLifetime ( lifetime  ) 

Enter description here...

Parameters:
int $lifetime
Returns:
Varien_Simplexml_Config

Definition at line 270 of file Config.php.

00271     {
00272         $this->_cacheLifetime = $lifetime;
00273         return $this;
00274     }

setCacheSaved ( flag  ) 

Enter description here...

Parameters:
boolean $flag
Returns:
Varien_Simplexml_Config

Definition at line 204 of file Config.php.

00205     {
00206         $this->_cacheSaved = $flag;
00207         return $this;
00208     }

setCacheTags ( tags  ) 

Enter description here...

Parameters:
array $tags
Returns:
Varien_Simplexml_Config

Definition at line 248 of file Config.php.

00249     {
00250         $this->_cacheTags = $tags;
00251         return $this;
00252     }

setNode ( path,
value,
overwrite = true 
)

Create node by $path and set its value.

Parameters:
string $path separated by slashes
string $value
boolean $overwrite
Returns:
Varien_Simplexml_Config

Definition at line 550 of file Config.php.

00551     {
00552         $xml = $this->_xml->setNode($path, $value, $overwrite);
00553         return $this;
00554     }

setXml ( Varien_Simplexml_Element node  ) 

Sets xml for this configuration

Parameters:
Varien_Simplexml_Element $sourceData
Returns:
Varien_Simplexml_Config

Definition at line 133 of file Config.php.

00134     {
00135         $this->_xml = $node;
00136         return $this;
00137     }

updateCacheChecksum ( data  ) 

Enter description here...

Parameters:
string $data
Returns:
Varien_Simplexml_Config

Definition at line 310 of file Config.php.

00311     {
00312         if (false===$this->getCacheChecksum()) {
00313             return $this;
00314         }
00315         if (false===$data || 0===$data) {
00316             $this->_cacheChecksum = false;
00317         } else {
00318             $this->setCacheChecksum($this->getCacheChecksum().':'.$data);
00319         }
00320         return $this;
00321     }

validateCacheChecksum (  ) 

Enter description here...

Returns:
boolean

Definition at line 358 of file Config.php.

00359     {
00360         $newChecksum = $this->getCacheChecksum();
00361         if (false===$newChecksum) {
00362             return false;
00363         }
00364         if (is_null($newChecksum)) {
00365             return true;
00366         }
00367         $cachedChecksum = $this->getCache()->load($this->getCacheChecksumId());
00368         return $newChecksum===false && $cachedChecksum===false || $newChecksum===$cachedChecksum;
00369     }


Member Data Documentation

$_cache = null [protected]

Definition at line 85 of file Config.php.

$_cacheChecksum = false [protected]

Definition at line 71 of file Config.php.

$_cacheId = null [protected]

Definition at line 50 of file Config.php.

$_cacheLifetime = null [protected]

Definition at line 64 of file Config.php.

$_cacheSaved = false [protected]

Definition at line 78 of file Config.php.

$_cacheTags = array() [protected]

Definition at line 57 of file Config.php.

$_elementClass = 'Varien_Simplexml_Element' [protected]

Definition at line 92 of file Config.php.

$_xml = null [protected]

Definition at line 43 of file Config.php.

$_xpathExtends = "//*[@extends]" [protected]

Definition at line 99 of file Config.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:25:04 2009 for Magento by  doxygen 1.5.8