From: <gem...@li...> - 2013-01-09 17:31:00
|
Revision: 1091 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1091&view=rev Author: matijsdejong Date: 2013-01-09 17:30:52 +0000 (Wed, 09 Jan 2013) Log Message: ----------- Made Renderer and Echo __PHP_Incomplete_Class proof Added documentation and disableOnLoad to ModelAbstract Switched ZFDebug to jQuery 1.8.3 Made CachedLoader that does not seem to speed things up Prepared switch to using pluginloader for LoaderAbstract and removing $GEMS_DIR from pre_bootstrap.php Modified Paths: -------------- trunk/library/classes/Gems/Loader/LoaderAbstract.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/Echo.php trunk/library/classes/MUtil/Html/Renderer.php trunk/library/classes/MUtil/Loader/CachedLoader.php trunk/library/classes/MUtil/Model/ModelAbstract.php trunk/library/classes/ZFDebug/Controller/Plugin/Debug.php trunk/library/pre_bootstrap.php Modified: trunk/library/classes/Gems/Loader/LoaderAbstract.php =================================================================== --- trunk/library/classes/Gems/Loader/LoaderAbstract.php 2013-01-07 16:04:05 UTC (rev 1090) +++ trunk/library/classes/Gems/Loader/LoaderAbstract.php 2013-01-09 17:30:52 UTC (rev 1091) @@ -85,7 +85,7 @@ /** * - * @var MUtil_Loader_CachedLoader + * @var Zend_Loader_PluginLoader_Interface */ private $_loader; @@ -107,16 +107,24 @@ $this->_dirs = $dirs; - // Set the directories to the used cascade pattern if ($this->cascade) { foreach ($dirs as $prefix => $path) { $newdirs[$prefix . '_' . $this->cascade] = $path; + // $newdirs[$prefix . '_' . $this->cascade] = $path . '/' . str_replace('_', '/', $this->cascade); } $this->_dirs = $newdirs; } - $this->_loader = MUtil_Loader_CachedLoader::getInstance(); + //$this->_loader = new Zend_Loader_PluginLoader($this->_dirs); + //* + // Set the directories to the used cascade pattern + $this->_loader = new Zend_Loader_PluginLoader(); + foreach (array_reverse($this->_dirs) as $prefix => $path) { + $this->_loader->addPrefixPath($prefix, $path . '/' . str_replace('_', '/', $prefix)); + } + // */ + if (MUtil_Registry_Source::$verbose) { MUtil_Echo::r($this->_dirs, '$this->_dirs in ' . get_class($this) . '->' . __FUNCTION__ . '():'); } @@ -166,6 +174,55 @@ */ protected function _loadClass($name, $create = false, array $arguments = array()) { + /* + $className = $this->_loader->load($name); + + // MUtil_Echo::track($className); + + if (is_subclass_of($className, __CLASS__)) { + $create = true; + // error_log($className); + $arguments = array($this->_containers[0], $this->_dirs); + + } elseif (is_subclass_of($className, 'MUtil_Registry_TargetInterface')) { + $create = true; + } + + if ($create) { + switch (count($arguments)) { + case 0: + $obj = new $className(); + break; + + case 1: + $obj = new $className($arguments[0]); + break; + + case 2: + $obj = new $className($arguments[0], $arguments[1]); + break; + + case 3: + $obj = new $className($arguments[0], $arguments[1], $arguments[2]); + break; + + default: + throw new Gems_Exception_Coding(__CLASS__ . '->' . __FUNCTION__ . ' cannot create class with ' . count($arguments) . ' parameters.'); + } + } else { + $obj = new MUtil_Lazy_StaticCall($className); + } + + if ($obj instanceof MUtil_Registry_TargetInterface) { + // error_log(get_class($obj)); + if ((! $this->applySource($obj)) && parent::$verbose) { + MUtil_Echo::track("Source apply to object of type $name failed."); + } + } + + return $obj; + // */ + // echo $name . ($create ? ' create' : ' not created') . "<br/>\n"; $cname = trim(str_replace('/', '_', ucfirst($name)), '_'); @@ -194,7 +251,7 @@ $paths = array($paths); } foreach ($paths as $path) { - //* + /* $className = $prefix . $cname; if ($this->_loader->loadClass($className, $path . $fprefix . '/' . $cfile)) { @@ -218,8 +275,9 @@ break 2; } // */ - /* + //* if ($obj = $this->_loadClassPath($path . $fprefix . '/' . $cfile, $prefix . $cname, $create, $arguments)) { + MUtil_Echo::track($prefix . $cname); $found = true; $this->_loaded[$cname] = get_class($obj); break 2; Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2013-01-07 16:04:05 UTC (rev 1090) +++ trunk/library/classes/GemsEscort.php 2013-01-09 17:30:52 UTC (rev 1091) @@ -95,10 +95,6 @@ { parent::__construct($application); - $autoloader = Zend_Loader_Autoloader::getInstance(); - $cachedloader = MUtil_Loader_CachedLoader::getInstance(GEMS_ROOT_DIR . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'cache'); - $autoloader->setDefaultAutoloader(array($cachedloader, 'loadClassByPaths')); - self::$_instanceOfSelf = $this; $firebug = $application->getOption('firebug'); @@ -315,6 +311,23 @@ protected function _initLoader() { global $GEMS_DIRS; + + /* + $dirs = $this->getOption('loaderDirs'); + + if (! $dirs) { + + $dirs = array(); + + foreach ($GEMS_DIRS as $prefix => $dir) { + $dirs[$prefix] = $dir . '/' . str_replace('_', '/', $prefix); + } + } + + MUtil_Echo::track($dirs); + + return $this->createProjectClass('Loader', $this->getContainer(), array_reverse($dirs)); + // */ return $this->createProjectClass('Loader', $this->getContainer(), $GEMS_DIRS); } @@ -555,7 +568,8 @@ 'Memory', 'Time', 'Registry', - 'Exception') + 'Exception'), + // 'jquery_path' => not yet initialized ); # Instantiate the database adapter and setup the plugin. Modified: trunk/library/classes/MUtil/Echo.php =================================================================== --- trunk/library/classes/MUtil/Echo.php 2013-01-07 16:04:05 UTC (rev 1090) +++ trunk/library/classes/MUtil/Echo.php 2013-01-09 17:30:52 UTC (rev 1091) @@ -154,7 +154,7 @@ { $session = self::getSession(); - if (is_array($var) || is_object($var)) { + if (is_array($var) || is_object($var) || ($var instanceof __PHP_Incomplete_Class)) { ob_start(); var_dump($var); $content = ob_get_clean(); Modified: trunk/library/classes/MUtil/Html/Renderer.php =================================================================== --- trunk/library/classes/MUtil/Html/Renderer.php 2013-01-07 16:04:05 UTC (rev 1090) +++ trunk/library/classes/MUtil/Html/Renderer.php 2013-01-09 17:30:52 UTC (rev 1091) @@ -196,6 +196,11 @@ // $new_content = 'WARNING: Object of type ' . get_class($content) . ' cannot be converted to string.'; throw new MUtil_Html_HtmlException('WARNING: Object of type ' . get_class($content) . ' cannot be converted to string.'); } + + } elseif ($content instanceof __PHP_Incomplete_Class) { + MUtil_Echo::track($content); + return ''; + } else { $new_content = (string) $content; } Modified: trunk/library/classes/MUtil/Loader/CachedLoader.php =================================================================== --- trunk/library/classes/MUtil/Loader/CachedLoader.php 2013-01-07 16:04:05 UTC (rev 1090) +++ trunk/library/classes/MUtil/Loader/CachedLoader.php 2013-01-09 17:30:52 UTC (rev 1091) @@ -50,26 +50,45 @@ * * @var array */ - protected $_cacheArray = array(); + private $_cacheClassArray = array(); /** * + * @var array + */ + // private $_cacheFileArray = array(); + + /** + * + * @var boolean + */ + private $_cacheChanged = false; + + /** + * Unix timestamp cahce file load time + * + * @var int + */ + private $_cacheLoadTime; + + /** + * * @var string */ - protected $_cacheDir = null; + private $_cacheDir = null; /** * * @var string */ - protected $_cacheFile = 'cached.loader.mutil.php'; + private $_cacheFile = 'cached.loader.mutil.php'; /** * An array containg include dir pathNames * * @var array */ - protected $_includeDirs; + private $_includeDirs; /** * @@ -93,7 +112,10 @@ } if (! file_exists($this->_cacheFile)) { - $this->_saveCache(); + $this->_cacheChanged = true; + $this->_cacheLoadTime = 0; + + // $this->_saveCache(); } else { if (! is_writable($this->_cacheFile)) { throw new Zend_Exception(sprintf('Cache file %s not writeable.', $this->_cacheFile)); @@ -107,6 +129,14 @@ } /** + * Make sure the changes ot the cache are saved. + */ + public function __destruct() + { + $this->_saveCache(); + } + + /** * Check for file existence and append status to the cache * * @param mixed $file String path to file or false if does not exist @@ -114,25 +144,18 @@ */ protected function _checkFile($file) { - if (array_key_exists($file, $this->_cacheArray)) { - return $this->_cacheArray[$file]; + return file_exists($file); + /* + if (array_key_exists($file, $this->_cacheFileArray)) { + return $this->_cacheFileArray[$file]; } // MUtil_Echo::track($file); - $this->_cacheArray[$file] = file_exists($file); + $this->_cacheFileArray[$file] = file_exists($file); + $this->_cacheChanged = true; - if (! file_exists($this->_cacheFile)) { - $this->_saveCache(); - } else { - if (false === $this->_cacheArray[$file]) { - $content = "\$this->_cacheArray['$file'] = false;\n"; - } else { - $content = "\$this->_cacheArray['$file'] = true;\n"; - } - file_put_contents($this->_cacheFile, $content, FILE_APPEND | LOCK_EX ); - } - - return $this->_cacheArray[$file]; + return $this->_cacheFileArray[$file]; + // */ } /** @@ -142,10 +165,16 @@ { include $this->_cacheFile; - // Include path has changed - if (!isset($include) || (get_include_path() != $include)) { - $this->_cacheArray = array(); + // if (isset($cacheArray, $fileArray, $include) && (get_include_path() != $include)) { + if (isset($cacheArray, $include) && (get_include_path() != $include)) { + $this->_cacheClassArray = $classArray; + // $this->_cacheFileArray = $fileArray; + $this->_cacheLoadTime = filemtime($this->_cacheFile); } + + $this->_cacheClassArray = array(); + // $this->_cacheFileArray = array(); + $this->_cacheChanged = true; } /** @@ -164,20 +193,50 @@ } /** - * Save the cache to file + * Save the cache to file (if changed) */ protected function _saveCache() { - $content = "<?php\n\n"; - $content .= "\$include = '" . get_include_path() . "';\n\n"; + // MUtil_Echo::track(filemtime($this->_cacheFile), $this->_cacheLoadTime, $this->_cacheChanged); + if (file_exists($this->_cacheFile)) { + if ((! $this->_cacheChanged) && (filemtime($this->_cacheFile) >= $this->_cacheLoadTime)) { + return; + } + } + /* + MUtil_Echo::r('Saving load cache (from previous call)'); - foreach ($this->_cacheArray as $file => $exists) { - if (false === $file) { - $content .= "\$this->_cacheArray['$file'] = false;\n"; + include $this->_cacheFile; + + MUtil_Echo::r(array_diff(array_keys($this->_cacheClassArray), array_keys($classArray))); + // */ + + $content = "<?php\n"; + $content .= "\$include = '" . get_include_path() . "';\n"; + + ksort($this->_cacheClassArray); + + $content .= "\$classArray = array(\n"; + foreach ($this->_cacheClassArray as $class => $file) { + $content .= "'$class' => '$file',\n"; + } + $content .= ");\n"; + + /* + ksort($this->_cacheFileArray); + + $content .= "\$fileArray = array(\n"; + + foreach ($this->_cacheFileArray as $file => $exists) { + if (false === $exists) { + $content .= "'$file' => false,\n"; } else { - $content .= "\$this->_cacheArray['$file'] = true;\n"; + $content .= "'$file' => true,\n"; } } + $content .= ");"; + // */ + file_put_contents($this->_cacheFile, $content, LOCK_EX); } @@ -269,6 +328,10 @@ if (! $instance) { $instance = new self($dir); + + if (is_subclass_of('Zend_Loader', 'MUtil_Loader_LoaderMarkerInterface')) { + Zend_Loader::setCachedLoader($instance); + } } return $instance;; @@ -281,7 +344,7 @@ */ public function includeFile($file) { - if ($this->_checkFile($file)) { + if (file_exists($file)) { $result = include $file; return $result ? $result : true; @@ -299,18 +362,35 @@ */ public function loadClass($className, $file) { + if (isset($this->_cacheClassArray[$className])) { + if ($this->_cacheClassArray[$className]) { + $this->includeFile($this->_cacheClassArray[$className]); + + return true; + } else { + // return false; + } + } + if (class_exists($className, false) || interface_exists($className, false)) { return true; } if ($this->includeFile($file)) { if (class_exists($className, false) || interface_exists($className, false)) { + $this->_cacheClassArray[$className] = $file; + $this->_cacheChanged = true; return true; } throw new Zend_Exception("The file '$file' does not contain the class '$class'."); } + if (! isset($this->_cacheClassArray[$className])) { + $this->_cacheClassArray[$className] = ''; + $this->_cacheChanged = true; + } + return false; } @@ -355,38 +435,26 @@ } $file .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; - if (null === $dirs) { - $dirs = $this->_includeDirs; + if (isset($this->_cacheClassArray[$class])) { + if ($this->_cacheClassArray[$class]) { + $this->includeFile($this->_cacheClassArray[$class]); + } } else { - $dirs = array_merge($dirs, $this->_includeDirs); - } + if (null === $dirs) { + $dirs = $this->_includeDirs; + } else { + $dirs = array_merge($dirs, $this->_includeDirs); + } - foreach ($dirs as $dir) { - // error_log($dir . $file); - if ($this->includeFile($dir . $file)) { - break; + foreach ($dirs as $dir) { + // error_log($dir . $file); + if ($this->includeFile($dir . $file)) { + $this->_cacheClassArray[$class] = $dir . $file; + $this->_cacheChanged = true; + break; + } } } - /* - if (!empty($dirs)) { - // use the autodiscovered path - $dirPath = dirname($file); - if (is_string($dirs)) { - $dirs = explode(PATH_SEPARATOR, $dirs); - } - foreach ($dirs as $key => $dir) { - if ($dir == '.') { - $dirs[$key] = $dirPath; - } else { - $dir = rtrim($dir, '\\/'); - $dirs[$key] = $dir . DIRECTORY_SEPARATOR . $dirPath; - } - } - $file = basename($file); - self::loadFile($file, $dirs, true); - } else { - self::loadFile($file, null, true); - } // */ if (!class_exists($class, false) && !interface_exists($class, false)) { require_once 'Zend/Exception.php'; Modified: trunk/library/classes/MUtil/Model/ModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/ModelAbstract.php 2013-01-07 16:04:05 UTC (rev 1090) +++ trunk/library/classes/MUtil/Model/ModelAbstract.php 2013-01-09 17:30:52 UTC (rev 1091) @@ -390,6 +390,13 @@ return $this; } + /** + * Delete all, one or some values for a certain field name. + * + * @param string $name Field name + * @param string|array|null $arrayOrKey1 Null or the name of a single attribute or an array of attribute names + * @param string $key2 Optional a second attribute name. + */ public function del($name, $arrayOrKey1 = null, $key2 = null) { if (func_num_args() == 1) { @@ -406,6 +413,18 @@ } /** + * Disable tyhe onload settings. This is sometimes needed for speed/ + * + * @return MUtil_Model_ModelAbstract (continuation pattern) + */ + public function disableOnLoad() + { + $this->setMeta(self::LOAD_TRANSFORMER, false); + + return $this; + } + + /** * Delete items from the model * * @param mixed $filter True to use the stored filter, array to specify a different filter Modified: trunk/library/classes/ZFDebug/Controller/Plugin/Debug.php =================================================================== --- trunk/library/classes/ZFDebug/Controller/Plugin/Debug.php 2013-01-07 16:04:05 UTC (rev 1090) +++ trunk/library/classes/ZFDebug/Controller/Plugin/Debug.php 2013-01-09 17:30:52 UTC (rev 1091) @@ -3,7 +3,7 @@ /** * 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 @@ -14,7 +14,7 @@ * * 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 @@ -65,10 +65,10 @@ 'Time' => null, 'Memory' => null), 'z-index' => 255, - 'jquery_path' => 'https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', + 'jquery_path' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', 'image_path' => null ); - + /** * Standard plugins * @@ -107,7 +107,7 @@ $this->setOptions($options); } - + /** * Creating ZF Version Tab always shown */ @@ -122,7 +122,7 @@ */ $this->_loadPlugins(); } - + /** * Sets options of the Debug Bar * @@ -142,7 +142,7 @@ if (isset($options['image_path'])) { $this->_options['image_path'] = $options['image_path']; } - + if (isset($options['plugins'])) { $this->_options['plugins'] = $options['plugins']; } @@ -183,7 +183,7 @@ } return $this; } - + /** * Get a registered plugin in the Debug Bar * @@ -198,7 +198,7 @@ } return false; } - + /** * Defined by Zend_Controller_Plugin_Abstract */ @@ -440,7 +440,7 @@ jQuery.noConflict(); ZFDebugCollapsed(); }; - + function ZFDebugCollapsed() { if ('.$collapsed.' == 1) { ZFDebugPanel(); @@ -448,7 +448,7 @@ return jQuery("#ZFDebug_debug").css("left", "-"+parseInt(jQuery("#ZFDebug_debug").outerWidth()-jQuery("#ZFDebug_toggler").outerWidth()+1)+"px"); } } - + function ZFDebugPanel(name) { jQuery(".ZFDebug_panel").each(function(i){ if(jQuery(this).css("display") == "block") { Modified: trunk/library/pre_bootstrap.php =================================================================== --- trunk/library/pre_bootstrap.php 2013-01-07 16:04:05 UTC (rev 1090) +++ trunk/library/pre_bootstrap.php 2013-01-09 17:30:52 UTC (rev 1091) @@ -67,21 +67,24 @@ 'Gems' => GEMS_LIBRARY_DIR . '/classes' ); -// Zend_Application: loads the autoloader -require_once 'Zend/Application.php'; +// Set up autoload +require_once 'Zend/Loader/AutoLoader.php'; +$autoloader = Zend_Loader_Autoloader::getInstance(); +$autoloader->registerNamespace('MUtil_'); +$autoloader->registerNamespace('Gems_'); +$autoloader->registerNamespace(GEMS_PROJECT_NAME_UC . '_'); +// Start using cached Loader +// require_once 'MUtil/Loader/CachedLoader.php'; +// $cachedloader = MUtil_Loader_CachedLoader::getInstance(GEMS_ROOT_DIR . '\var\cache'); +// $autoloader->setDefaultAutoloader(array($cachedloader, 'loadClassByPaths')); + // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); -// Set up autoload (included by Zend_Application). -$autoloader = Zend_Loader_Autoloader::getInstance(); -$autoloader->registerNamespace('MUtil_'); -$autoloader->registerNamespace('Gems_'); -$autoloader->registerNamespace(GEMS_PROJECT_NAME_UC . '_'); - // MUtil_Model::$verbose = true; $application->bootstrap() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |