00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Varien 00022 * @package Varien_Simplexml 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 00028 /** 00029 * Abstract class for configuration cache 00030 * 00031 * @category Varien 00032 * @package Varien_Simplexml 00033 * @author Magento Core Team <core@magentocommerce.com> 00034 */ 00035 abstract class Varien_Simplexml_Config_Cache_Abstract extends Varien_Object 00036 { 00037 /** 00038 * Constructor 00039 * 00040 * Initializes components and allows to save the cache 00041 * 00042 * @param array $data 00043 */ 00044 public function __construct($data=array()) 00045 { 00046 parent::__construct($data); 00047 00048 $this->setComponents(array()); 00049 $this->setIsAllowedToSave(true); 00050 } 00051 00052 /** 00053 * Add configuration component to stats 00054 * 00055 * @param string $component Filename of the configuration component file 00056 * @return Varien_Simplexml_Config_Cache_Abstract 00057 */ 00058 public function addComponent($component) 00059 { 00060 $comps = $this->getComponents(); 00061 if (is_readable($component)) { 00062 $comps[$component] = array('mtime'=>filemtime($component)); 00063 } 00064 $this->setComponents($comps); 00065 00066 return $this; 00067 } 00068 00069 /** 00070 * Validate components in the stats 00071 * 00072 * @param array $data 00073 * @return boolean 00074 */ 00075 public function validateComponents($data) 00076 { 00077 if (empty($data) || !is_array($data)) { 00078 return false; 00079 } 00080 // check that no source files were changed or check file exsists 00081 foreach ($data as $sourceFile=>$stat) { 00082 if (empty($stat['mtime']) || !is_file($sourceFile) || filemtime($sourceFile)!==$stat['mtime']) { 00083 return false; 00084 } 00085 } 00086 return true; 00087 } 00088 00089 public function getComponentsHash() 00090 { 00091 $sum = ''; 00092 foreach ($this->getComponents() as $comp) { 00093 $sum .= $comp['mtime'].':'; 00094 } 00095 $hash = md5($sum); 00096 return $hash; 00097 } 00098 }