From: <gem...@li...> - 2013-01-03 17:24:07
|
Revision: 1087 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1087&view=rev Author: matijsdejong Date: 2013-01-03 17:23:59 +0000 (Thu, 03 Jan 2013) Log Message: ----------- Added info to ProjectInformationAction.php Made a non-functional start on CachedLoader.php Modified Paths: -------------- trunk/library/classes/Gems/Default/ProjectInformationAction.php trunk/library/classes/Gems/Loader/LoaderAbstract.php Added Paths: ----------- trunk/library/classes/MUtil/Loader/ trunk/library/classes/MUtil/Loader/CachedLoader.php Modified: trunk/library/classes/Gems/Default/ProjectInformationAction.php =================================================================== --- trunk/library/classes/Gems/Default/ProjectInformationAction.php 2013-01-03 08:22:06 UTC (rev 1086) +++ trunk/library/classes/Gems/Default/ProjectInformationAction.php 2013-01-03 17:23:59 UTC (rev 1087) @@ -136,7 +136,8 @@ $data[$this->_('Gems version')] = $versions->getGemsVersion(); $data[$this->_('Gems build')] = $versions->getBuild(); $data[$this->_('Gems project')] = GEMS_PROJECT_NAME; - $data[$this->_('Gems web directory')] = GEMS_ROOT_DIR; + $data[$this->_('Gems web directory')] = GEMS_WEB_DIR; + $data[$this->_('Gems root directory')] = GEMS_ROOT_DIR; $data[$this->_('Gems code directory')] = GEMS_LIBRARY_DIR; $data[$this->_('MUtil version')] = MUtil_Version::get(); $data[$this->_('Zend version')] = Zend_Version::VERSION; Modified: trunk/library/classes/Gems/Loader/LoaderAbstract.php =================================================================== --- trunk/library/classes/Gems/Loader/LoaderAbstract.php 2013-01-03 08:22:06 UTC (rev 1086) +++ trunk/library/classes/Gems/Loader/LoaderAbstract.php 2013-01-03 17:23:59 UTC (rev 1087) @@ -162,6 +162,8 @@ $cname = trim(str_replace('/', '_', ucfirst($name)), '_'); $cfile = str_replace('_', '/', $cname) . '.php'; + // MUtil_Loader_CachedLoader::getInstance(GEMS_ROOT_DIR . '\var\cache'); + $found = false; /** @@ -189,7 +191,7 @@ $found = true; $this->_loaded[$cname] = get_class($obj); break 2; - } + } } } } Added: trunk/library/classes/MUtil/Loader/CachedLoader.php =================================================================== --- trunk/library/classes/MUtil/Loader/CachedLoader.php (rev 0) +++ trunk/library/classes/MUtil/Loader/CachedLoader.php 2013-01-03 17:23:59 UTC (rev 1087) @@ -0,0 +1,165 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package MUtil + * @subpackage Loader + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: CachedLoader.php$ + */ + +/** + * + * + * @package MUtil + * @subpackage Loader + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since MUtil version 1.2 + */ +class MUtil_Loader_CachedLoader +{ + /** + * + * @var array + */ + protected $_cacheArray = array(); + + /** + * + * @var string + */ + protected $_cacheDir = null; + + /** + * + * @var string + */ + protected $_cacheFile = 'cached.loader.mutil.php'; + + /** + * + * @param string $dir + */ + protected function __construct($dir = null) + { + if (null === $dir) { + $dir = getenv('TMP'); + } + + $this->_cacheDir = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR; + $this->_cacheFile = $this->_cacheDir . $this->_cacheFile; + + if (! file_exists($this->_cacheDir)) { + throw new Zend_Exception(sprintf('Cache directory %s does not exist.', $this->_cacheDir)); + } + + if (! is_writable($this->_cacheDir)) { + throw new Zend_Exception(sprintf('Cache directory %s is not writeable.', $this->_cacheFile)); + } + + if (! file_exists($this->_cacheFile)) { + $this->_saveCache(); + } else { + if (! is_writable($this->_cacheFile)) { + throw new Zend_Exception(sprintf('Cache file %s not writeable.', $this->_cacheFile)); + } + + $this->_loadCache(); + } + // MUtil_Echo::track($this->_cacheFile, $this->_cacheDir, file_exists($this->_cacheDir)); + } + + /** + * Append a new found file to the cache + * + * @param string $class The name of the class to load + * @param mixed $file String path to file or false if does not exist + */ + protected function _appendToCache($class, $file) + { + $this->_cacheArray[$class] = $file; + + if (! file_exists($this->_cacheFile)) { + $this->_saveCache(); + } else { + if (false === $file) { + $content = "\$this->_cacheArray['$class'] = false;\n"; + } else { + $content = "\$this->_cacheArray['$class'] = '$file';\n"; + } + file_put_contents($this->_cacheFile, $content, FILE_APPEND | LOCK_EX ); + } + } + + protected function _loadCache() + { + include $this->_cacheFile; + } + + protected function _saveCache() + { + $content = "<?php\n"; + + foreach ($this->_cacheArray as $class => $file) { + if (false === $file) { + $content .= "\$this->_cacheArray['$class'] = false;\n"; + } else { + $content .= "\$this->_cacheArray['$class'] = '$file';\n"; + } + } + file_put_contents($this->_cacheFile, $content, LOCK_EX); + } + + /** + * + * @static MUtil_Loader_CachedLoader $instance + * @param stirng $dir + * @return MUtil_Loader_CachedLoader + */ + public static function getInstance($dir = null) + { + static $instance; + + if (! $instance) { + $instance = new self($dir); + } + + return $instance;; + } + + protected function isClass($className, $paths) + { + // Zend_Loader::standardiseFile($file) + //if (file_exists($path . $className)) { + +// /} + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |