From: <gem...@li...> - 2013-01-10 16:43:46
|
Revision: 1092 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1092&view=rev Author: matijsdejong Date: 2013-01-10 16:43:36 +0000 (Thu, 10 Jan 2013) Log Message: ----------- ZFDebug now set from application.ini and JQuery local aware $GEMS_DIRS no longer used (except as backup) new SnippetLoaderInterface using pluginsLoader Modified Paths: -------------- trunk/library/changelog.txt trunk/library/classes/Gems/Events.php trunk/library/classes/Gems/Loader/LoaderAbstract.php trunk/library/classes/Gems/Project/ProjectSettings.php trunk/library/classes/Gems/Snippets/SnippetLoader.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/Loader/CachedLoader.php trunk/library/classes/MUtil/Snippets/SnippetLoader.php trunk/library/classes/MUtil/Snippets/SnippetLoaderInterface.php trunk/library/classes/ZFDebug/Controller/Plugin/Debug.php trunk/library/pre_bootstrap.php Added Paths: ----------- trunk/library/classes/MUtil/Loader/PluginLoader.php Modified: trunk/library/changelog.txt =================================================================== --- trunk/library/changelog.txt 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/changelog.txt 2013-01-10 16:43:36 UTC (rev 1092) @@ -2,6 +2,8 @@ ============================================================ Defined constant GEMS_PROJECT_PATH removed from code (update at least your application.ini and use APPLICATION_PATH instead) Moved date_default_timezone_set to index.php (can generate warnings) +The global variable $GEMS_DIRS is deprecated, redefine it the application.ini using loaderDirs.Gems = .... (see NewProject) +ZFDebug is now activated in the application.ini using: zfdebug.activate = 1 Important changes from 1.5.6 => 1.5.7 ============================================================ Modified: trunk/library/classes/Gems/Events.php =================================================================== --- trunk/library/classes/Gems/Events.php 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/classes/Gems/Events.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -46,8 +46,6 @@ */ class Gems_Events extends Gems_Loader_TargetLoaderAbstract { - const EVENTS_DIR = 'Event'; - const TRACK_COMPLETION_EVENT = 'Track/Completed'; const ROUND_CHANGED_EVENT = 'Round/Changed'; const SURVEY_BEFORE_ANSWERING_EVENT = 'Survey/BeforeAnswering'; @@ -96,22 +94,19 @@ /** * - * @global array $GEMS_DIRS An array of directories that specify where to look for code. * @param string $eventType An event subdirectory (may contain multiple levels split by '/' * @return array An array of type prefix => classname */ protected function _getEventDirs($eventType) { - global $GEMS_DIRS; - $eventClass = str_replace('/', '_', $eventType); - foreach ($GEMS_DIRS as $name => $dir) { - $prefix = $name . '_' . self::EVENTS_DIR . '_' . $eventClass . '_'; - $paths[$prefix] = $dir . '/' . $name . '/' . self::EVENTS_DIR . '/' . $eventType; + foreach ($this->_dirs as $name => $dir) { + $prefix = $name . '_' . $eventClass . '_'; + $paths[$prefix] = $dir . DIRECTORY_SEPARATOR . $eventType; } - $paths[''] = APPLICATION_PATH . '/' . strtolower(self::EVENTS_DIR . 's/' . $eventType); - // MUtil_Echo::track($paths); + $paths[''] = APPLICATION_PATH . '/events/' . strtolower($eventType); + MUtil_Echo::track($paths); return $paths; } @@ -182,7 +177,7 @@ if (! class_exists($eventName, true)) { // Autoload is used for Zend standard defined classnames, // so if the class is not autoloaded, define the path here. - $filename = APPLICATION_PATH . '/' . strtolower(self::EVENTS_DIR . 's/' . $eventType) . '/' . $eventName . '.php'; + $filename = APPLICATION_PATH . '/events/' . strtolower($eventType) . '/' . $eventName . '.php'; if (! file_exists($filename)) { throw new Gems_Exception_Coding("The event '$eventName' of type '$eventType' does not exist at location: $filename."); Modified: trunk/library/classes/Gems/Loader/LoaderAbstract.php =================================================================== --- trunk/library/classes/Gems/Loader/LoaderAbstract.php 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/classes/Gems/Loader/LoaderAbstract.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -76,20 +76,12 @@ protected $_dirs; /** - * This array holds a cache of requested class -> resulting classname pairs so we don't have - * to check all prefixes and paths over and over again * - * @var array classname->resulting class + * @var MUtil_Loader_PluginLoader */ - private $_loaded = array(); + protected $_loader; /** - * - * @var Zend_Loader_PluginLoader_Interface - */ - private $_loader; - - /** * Allows sub classes of Gems_Loader_LoaderAbstract to specify the subdirectory where to look for. * * @var string $cascade An optional subdirectory where this subclass always loads from. @@ -109,22 +101,13 @@ if ($this->cascade) { foreach ($dirs as $prefix => $path) { - $newdirs[$prefix . '_' . $this->cascade] = $path; - // $newdirs[$prefix . '_' . $this->cascade] = $path . '/' . str_replace('_', '/', $this->cascade); + $newdirs[$prefix . '_' . $this->cascade] = $path . '/' . strtr($this->cascade, '_', '/'); } $this->_dirs = $newdirs; } - //$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)); - } - // */ + $this->_loader = new MUtil_Loader_PluginLoader($this->_dirs); - if (MUtil_Registry_Source::$verbose) { MUtil_Echo::r($this->_dirs, '$this->_dirs in ' . get_class($this) . '->' . __FUNCTION__ . '():'); } @@ -174,180 +157,30 @@ */ 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 (! $create) { + return new MUtil_Lazy_StaticCall($className); } + $obj = $this->_loader->createClass($className, $arguments); + 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)), '_'); - $cfile = str_replace('_', '/', $cname) . '.php'; - - $found = false; - - /** - * First check if the class was already loaded - * If so, we don't have to try loading from the other paths - **/ - if (array_key_exists($cname, $this->_loaded) && $obj = $this->_loadClassPath('', $this->_loaded[$cname], $create, $arguments)) { - $found = true; - } - - if (!$found) { - foreach ($this->_dirs as $prefix => $paths) { - if (!empty($prefix)) { - $fprefix = '/' . str_replace('_', '/', $prefix); - $prefix .= '_'; - } else { - $fprefix = ''; - } - - if (!is_array($paths)) { - $paths = array($paths); - } - foreach ($paths as $path) { - /* - $className = $prefix . $cname; - - if ($this->_loader->loadClass($className, $path . $fprefix . '/' . $cfile)) { - if (is_subclass_of($className, __CLASS__)) { - $create = true; - $arguments = array($this->_containers[0], $this->_dirs); - - } elseif (is_subclass_of($className, 'MUtil_Registry_TargetInterface')) { - $create = true; - } - - - if ($create) { - $obj = $this->_loader->createClass($className, $arguments); - } else { - $obj = new MUtil_Lazy_StaticCall($className); - } - - $found = true; - $this->_loaded[$cname] = get_class($obj); - 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; - } // */ - } - } - } - - if ($found) { - 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; - } - - // Throw exception when not found - throw new Gems_Exception_Coding(__CLASS__ . '->' . __FUNCTION__ . ' cannot find class with name ' .$name . ' in ' . print_r($this->_dirs, true)); } - - /** - * Try the actual loading of the class. - * - * @param string $filepath The full path to the class - * @param string $classname The full class name. - * @param boolean $create Create the object, or only when an MUtil_Registry_TargetInterface instance. - * @param array $arguments Class initialization arguments. - * @return mixed Null or object of type $classname or MUtil_Lazy_StaticCall - */ - private function _loadClassPath($filepath, $classname, $create, array $arguments) - { - // echo '_loadClassPath: ' . $this->cascade . '-' . $classname . '-' . ($create ? 1 : 0) . "<br/>\n"; - // debug_print_backtrace(); - // MUtil_Echo::track($filepath, $classname, $this->cascade); - - if (! class_exists($classname, false)) { - if (file_exists($filepath)) { - // echo $classname . ' :: ' . $filepath . "<br/>\n"; - include_once($filepath); - } else { - return; - } - } - - if (is_subclass_of($classname, __CLASS__)) { - return new $classname($this->_containers[0], $this->_dirs); - - } elseif ($create || is_subclass_of($classname, 'MUtil_Registry_TargetInterface')) { - switch (count($arguments)) { - case 0: - return new $classname(); - - case 1: - return new $classname($arguments[0]); - - case 2: - return new $classname($arguments[0], $arguments[1]); - - case 3: - return new $classname($arguments[0], $arguments[1], $arguments[2]); - - default: - throw new Gems_Exception_Coding(__CLASS__ . '->' . __FUNCTION__ . ' cannot create class with ' . count($arguments) . ' parameters.'); - } - - } else { - return new MUtil_Lazy_StaticCall($classname); - } - } } \ No newline at end of file Modified: trunk/library/classes/Gems/Project/ProjectSettings.php =================================================================== --- trunk/library/classes/Gems/Project/ProjectSettings.php 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/classes/Gems/Project/ProjectSettings.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -533,4 +533,14 @@ { return isset($this['jquery'], $this['jquery']['local']); } + + /** + * Is this project use a multi locale project + * + * @return boolean + */ + public function isMultiLocale() + { + return (boolean) (isset($this['multiLocale']) && $this['multiLocale']); + } } \ No newline at end of file Modified: trunk/library/classes/Gems/Snippets/SnippetLoader.php =================================================================== --- trunk/library/classes/Gems/Snippets/SnippetLoader.php 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/classes/Gems/Snippets/SnippetLoader.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -57,66 +57,45 @@ */ protected $cascade = 'Snippets'; - protected $loader; - /** - * @var MUtil_Snippets_SnippetLoader - */ - protected $backup; - - /** - * Initialize the snippetloader (Gems style) + * Sets the source of variables and the first directory for snippets * - * @param mixed $container A container acting as source for MUtil_Registry_Source - * @param array $dirs The directories where to look for requested classes + * @param mixed $source Something that is or can be made into MUtil_Registry_SourceInterface, otheriwse Zend_Registry is used. + * @param array $dirs prefix => pathname The inital paths to load from */ - public function __construct($container = null, $dirs = array()) + public function __construct($source = null, array $dirs = array()) { - parent::__construct($container, $dirs); + parent::__construct($source, $dirs); - $this->backup = new MUtil_Snippets_SnippetLoader($this); - $this->addDirectory(GEMS_LIBRARY_DIR . '/classes/MUtil/Snippets/Standard'); - } - - - /** - * Add a directory to the front of the list of places where snippets are loaded from. - * - * @param string $dir - * @return MUtil_Snippets_SnippetLoader - */ - public function addDirectory($dir) - { - if (!array_key_exists('', $this->_dirs)) { - $this->_dirs[''] = array(); + $noPrefixDirs = array( + GEMS_LIBRARY_DIR . '/classes/MUtil/Snippets/Standard', + GEMS_LIBRARY_DIR . '/snippets', + GEMS_ROOT_DIR . '/application/snippets', + ); + foreach ($noPrefixDirs as $dir) { + if (file_exists($dir)) { + $this->_loader->addPrefixPath('', $dir); + } } - array_unshift($this->_dirs[''], $dir); - return $this->backup->addDirectory($dir); + // $this->_loader->addPrefixPath('MUtil_Snippets', GEMS_LIBRARY_DIR . '/classes/MUtil/Snippets/Standard'); } /** - * Add parameter values to the source for snippets. + * Add prefixed paths to the registry of paths * - * @param mixed $container_or_pairs This function can be called with either a single container or a list of name/value pairs. - * @return MUtil_Snippets_SnippetLoader + * @param string $prefix + * @param string $path + * @return MUtil_Snippets_SnippetLoaderInterface */ - public function addSource($container_or_pairs) + public function addPrefixPath($prefix, $path) { - return $this->backup->addSource($container_or_pairs); - } + $this->_loader->addPrefixPath($prefix, $path); - /** - * Returns the directories where snippets are loaded from. - * - * @param array $dirs - * @return array - */ - public function getDirectories() - { - return $this->backup->getDirectories(); + return $this; } + /** * Searches and loads a .php snippet file. * @@ -133,8 +112,6 @@ } catch (Exception $exc) { MUtil_Echo::track($exc->getMessage()); throw $exc; - //Class loading failed, now defer - //$snippet = $this->backup->getSnippet($filename, $extraSourceParameters); } return $snippet; @@ -147,18 +124,21 @@ */ public function getSource() { - return $this->backup->getSource(); + return $this; } /** - * Set the directories where snippets are loaded from. + * Remove a prefix (or prefixed-path) from the registry * - * @param array $dirs - * @return MUtil_Snippets_SnippetLoader (continuation pattern) + * @param string $prefix + * @param string $path OPTIONAL + * @return MUtil_Snippets_SnippetLoaderInterface */ - public function setDirectories(array $dirs) + public function removePrefixPath($prefix, $path = null) { - return $this->backup->setDirectories($dirs); + $this->_loader->removePrefixPath($prefix, $path); + + return $this; } /** @@ -169,6 +149,6 @@ */ public function setSource(MUtil_Registry_SourceInterface $source) { - return $this->backup->setSource($source); + throw new Gems_Exception_Coding('Cannot set source for ' . __CLASS__); } } \ No newline at end of file Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/classes/GemsEscort.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -51,41 +51,54 @@ */ class GemsEscort extends MUtil_Application_Escort { + /** + * Default reception code value + */ const RECEPTION_OK = 'OK'; + /** + * Static instance + * + * @var self + */ private static $_instanceOfSelf; + /** + * Targets for _updateVariable + * + * @var array + */ private $_copyDestinations; - private $_startFirebird; /** - * The menu variable + * The prefix / directory paths where the Gems Loaders should look * - * @var Gems_Menu + * @var array prefix => path */ - public $menu; + private $_loaderDirs; /** - * Copy from Zend_Translate_Adapter + * The project loader * - * Translates the given string - * returns the translation + * @var MUtil_Loader_PluginLoader + */ + private $_projectLoader; + + /** + * Is firebird logging on (set by constructor from application.ini) * - * @param string $text Translation string - * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale - * identifier, @see Zend_Locale for more information - * @return string + * @var boolean */ - public function _($text, $locale = null) - { - if (! isset($this->request)) { - // Locale is fixed by request. - $this->setException(new Gems_Exception_Coding('Requested translation before request was made available.')); - } - return $this->translate->getAdapter()->_($text, $locale); - } + private $_startFirebird; /** + * The menu variable + * + * @var Gems_Menu + */ + public $menu; + + /** * Constructor * * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application @@ -97,18 +110,73 @@ self::$_instanceOfSelf = $this; + // DIRECTORIES USED BY LOADER + $dirs = $this->getOption('loaderDirs'); + if (! $dirs) { + global $GEMS_DIRS; + + // Use $GEMS_DIRS if defined + if (isset($GEMS_DIRS)) { + $dirs = array(); + + foreach ($GEMS_DIRS as $prefix => $dir) { + $dirs[$prefix] = $dir . '/' . strtr($prefix, '_', '/'); + } + } else { + // Default setting + $dirs = array( + GEMS_PROJECT_NAME_UC => APPLICATION_PATH . '/classes/' .GEMS_PROJECT_NAME_UC, + 'Gems' => GEMS_LIBRARY_DIR . '/classes/Gems' + ); + } + } + // MUtil_Echo::track($dirs); + $this->_loaderDirs = array_reverse($dirs); + + // NAMESPACES + $autoloader = Zend_Loader_Autoloader::getInstance(); + foreach ($this->_loaderDirs as $prefix => $path) { + if ($prefix) { + $autoloader->registerNamespace($prefix . '_'); + } + } + + // PROJECT LOADER + $this->_projectLoader = new MUtil_Loader_PluginLoader($this->_loaderDirs); + + // FIRE BUG $firebug = $application->getOption('firebug'); $this->_startFirebird = $firebug['log']; + // START SESSIE $sessionOptions['name'] = GEMS_PROJECT_NAME_UC . '_' . md5(APPLICATION_PATH) . '_SESSID'; $sessionOptions['cookie_path'] = strtr(dirname($_SERVER['SCRIPT_NAME']), '\\', '/'); $sessionOptions['cookie_httponly'] = true; $sessionOptions['cookie_secure'] = (APPLICATION_ENV == 'production'); - Zend_Session::start($sessionOptions); } /** + * Copy from Zend_Translate_Adapter + * + * Translates the given string + * returns the translation + * + * @param string $text Translation string + * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale + * identifier, @see Zend_Locale for more information + * @return string + */ + public function _($text, $locale = null) + { + if (! isset($this->request)) { + // Locale is fixed by request. + $this->setException(new Gems_Exception_Coding('Requested translation before request was made available.')); + } + return $this->translate->getAdapter()->_($text, $locale); + } + + /** * Function to maintain uniformity of access to variables from the bootstrap object. * Copies all variables to the target object. * @@ -310,25 +378,7 @@ */ 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); + return $this->createProjectClass('Loader', $this->getContainer(), $this->_loaderDirs); } /** @@ -552,40 +602,47 @@ * Add ZFDebug info to the page output. * * @return void - * / + */ protected function _initZFDebug() { - // if ((APPLICATION_ENV === 'development') && - if ((APPLICATION_ENV !== 'production') && - (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') === FALSE)) { + if ((APPLICATION_ENV === 'production') && + (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.'))) { + // Never on on production systems, never for IE 6 + return; + } - $autoloader = Zend_Loader_Autoloader::getInstance(); - $autoloader->registerNamespace('ZFDebug'); + $debug = $this->getOption('zfdebug'); + if (! isset($debug['activate']) || ('1' !== $debug['activate'])) { + // Only turn on when activated + return; + } - $options = array( - 'plugins' => array('Variables', - 'File' => array('base_path' => '/path/to/project'), - 'Memory', - 'Time', - 'Registry', - 'Exception'), - // 'jquery_path' => not yet initialized - ); + $autoloader = Zend_Loader_Autoloader::getInstance(); + $autoloader->registerNamespace('ZFDebug'); - # Instantiate the database adapter and setup the plugin. - # Alternatively just add the plugin like above and rely on the autodiscovery feature. - $this->bootstrap('db'); - $db = $this->getPluginResource('db'); - $options['plugins']['Database']['adapter'] = $db->getDbAdapter(); + $options = array( + 'plugins' => array('Variables', + 'File' => array('base_path' => '/path/to/project'), + 'Memory', + 'Time', + 'Registry', + 'Exception'), + // 'jquery_path' => not yet initialized + ); - $debug = new ZFDebug_Controller_Plugin_Debug($options); + # Instantiate the database adapter and setup the plugin. + # Alternatively just add the plugin like above and rely on the autodiscovery feature. + $this->bootstrap('db'); + $db = $this->getPluginResource('db'); + $options['plugins']['Database']['adapter'] = $db->getDbAdapter(); - $this->bootstrap('frontController'); - $frontController = $this->getResource('frontController'); - $frontController->registerPlugin($debug); - } - }// */ + $debug = new ZFDebug_Controller_Plugin_Debug($options); + $this->bootstrap('frontController'); + $frontController = $this->getResource('frontController'); + $frontController->registerPlugin($debug); + } + /** * Function called if specified in the Project.ini layoutPrepare section before * the layout is drawn, but after the rest of the program has run it's course. @@ -1126,14 +1183,6 @@ { $this->_copyVariables($actionController ? $actionController : $this->controllerAfterAction); - // Ste the directories where the snippets are/ - if ($actionController instanceof MUtil_Controller_Action) { - $snippetLoader = $actionController->getSnippetLoader(); - $snippetLoader->addDirectory(GEMS_ROOT_DIR . '/library/Gems/snippets'); - $snippetLoader->addDirectory(APPLICATION_PATH . '/snippets'); - // MUtil_Echo::track($snippetLoader->getDirectories()); - } - $this->prepareController(); // Now set some defaults @@ -1151,32 +1200,20 @@ Zend_Registry::set(MUtil_Model_FormBridge::REGISTRY_KEY, array('date' => $dateFormOptions)); } + /** + * Creates an object of the specified className seareching the loader dirs path + * + * @param string $className + * @param mixed $paramOne Optional + * @param mixed $paramTwo Optional + * @return object + */ protected function createProjectClass($className, $paramOne = null, $paramTwo = null) { - $filename = APPLICATION_PATH . '/classes/' . GEMS_PROJECT_NAME_UC . '/'; - $filename .= str_replace('_', '/', $className) . '.php'; - if (file_exists($filename)) { - $className = GEMS_PROJECT_NAME_UC . '_' . $className; - } else { - $className = 'Gems_' . $className; - } + $arguments = func_get_args(); + array_shift($arguments); - switch (func_num_args()) - { - case 1: - return new $className(); - - case 2: - return new $className($paramOne); - - case 3: - return new $className($paramOne, $paramTwo); - - default: - throw new Gems_Exception_Coding( - __CLASS__ . '->' . __FUNCTION__ . '() called with more parameters than possible.' - ); - } + return $this->_projectLoader->createClass($className, $arguments); } /** @@ -1564,7 +1601,7 @@ */ public function requestChanged(Zend_Controller_Request_Abstract $request) { - if ($this->project->multiLocale) { + if ($this->project->isMultiLocale()) { // Get the choosen language $localeId = Gems_Cookies::getLocale($request); Modified: trunk/library/classes/MUtil/Loader/CachedLoader.php =================================================================== --- trunk/library/classes/MUtil/Loader/CachedLoader.php 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/classes/MUtil/Loader/CachedLoader.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -44,7 +44,7 @@ * @license New BSD License * @since Class available since MUtil version 1.2 */ -class MUtil_Loader_CachedLoader +class MUtil_Loader_CachedLoader implements Zend_Loader_Autoloader_Interface { /** * @@ -241,6 +241,46 @@ } /** + * Autoload a class + * + * @abstract + * @param string $class + * @return mixed + * False [if unable to load $class] + * get_class($class) [if $class is successfully loaded] + */ + public function autoload($class) + { + $className = ltrim($class, '\\'); + $file = ''; + $namespace = ''; + if ($lastNsPos = strripos($className, '\\')) { + $namespace = substr($className, 0, $lastNsPos); + $className = substr($className, $lastNsPos + 1); + $file = strtr($namespace, '\\', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + } + $file .= strtr($className, '_', DIRECTORY_SEPARATOR) . '.php'; + + if (isset($this->_cacheClassArray[$class])) { + if ($this->_cacheClassArray[$class]) { + return (boolean) $this->includeFile($this->_cacheClassArray[$class]); + } + } else { + $dirs = $this->_includeDirs; + + foreach ($dirs as $dir) { + // error_log($dir . $file); + if ($this->includeFile($dir . $file)) { + $this->_cacheClassArray[$class] = $dir . $file; + $this->_cacheChanged = true; + return true; + } + } + } + return false; + } + + /** * Create a new instance of a class * * @param string $className The name of the class @@ -341,13 +381,14 @@ * Include a file with cached existence check * * @param string $file The full path to the file + * @return mixed The load return value if available, "1" if loaded without return, false otherwise */ public function includeFile($file) { if (file_exists($file)) { $result = include $file; - return $result ? $result : true; + return $result ? $result : false; } return false; @@ -431,9 +472,9 @@ if ($lastNsPos = strripos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); - $file = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; + $file = strtr($namespace, '\\', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } - $file .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; + $file .= strtr($className, '_', DIRECTORY_SEPARATOR) . '.php'; if (isset($this->_cacheClassArray[$class])) { if ($this->_cacheClassArray[$class]) { Added: trunk/library/classes/MUtil/Loader/PluginLoader.php =================================================================== --- trunk/library/classes/MUtil/Loader/PluginLoader.php (rev 0) +++ trunk/library/classes/MUtil/Loader/PluginLoader.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -0,0 +1,128 @@ +<?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: PluginLoader.php$ + */ + +/** + * Extension of PluginLoader with class instantiation + * + * @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_PluginLoader extends Zend_Loader_PluginLoader +{ + /** + * Instantiate a new class using the arguments array for initiation + * + * @param string $className + * @param array $arguments Instanciation arguments + * @return className + */ + public function createClass($className, array $arguments = array()) + { + if (!class_exists($className)) { + $className = $this->load($className); + } + + switch (count($arguments)) { + case 0: + return new $className(); + + case 1: + return new $className( + $arguments[0] + ); + + case 2: + return new $className( + $arguments[0], $arguments[1] + ); + + case 3: + return new $className( + $arguments[0], $arguments[1], $arguments[2] + ); + + case 4: + return new $className( + $arguments[0], $arguments[1], $arguments[2], $arguments[3] + ); + + case 5: + return new $className( + $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4] + ); + + case 6: + return new $className( + $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], + $arguments[5] + ); + + case 7: + return new $className( + $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], + $arguments[5], $arguments[6] + ); + + case 8: + return new $className( + $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], + $arguments[5], $arguments[6], $arguments[7] + ); + + case 9: + return new $className( + $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], + $arguments[5], $arguments[6], $arguments[7], $arguments[8] + ); + + case 10: + return new $className( + $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], + $arguments[5], $arguments[6], $arguments[7], $arguments[8], $arguments[9] + ); + + default: + throw new Zend_Exception( + 'MUtil Plugin Loader cannot create a class with ' . + count($arguments) . ' parameters.' + ); + } + } +} Modified: trunk/library/classes/MUtil/Snippets/SnippetLoader.php =================================================================== --- trunk/library/classes/MUtil/Snippets/SnippetLoader.php 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/classes/MUtil/Snippets/SnippetLoader.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -48,6 +48,12 @@ class MUtil_Snippets_SnippetLoader implements MUtil_Snippets_SnippetLoaderInterface { /** + * + * @var MUtil_Loader_PluginLoader + */ + protected $loader; + + /** * The file locations where to look for snippets. * * Can be overruled in descendants @@ -67,118 +73,65 @@ * Sets the source of variables and the first directory for snippets * * @param mixed $source Something that is or can be made into MUtil_Registry_SourceInterface, otheriwse Zend_Registry is used. + * @param array $dirs prefix => pathname The inital paths to load from */ - public function __construct($source = null) + public function __construct($source = null, array $dirs = array()) { if (! $source instanceof MUtil_Registry_Source) { $source = new MUtil_Registry_Source($source); } $this->setSource($source); - $this->setDirectories(array(dirname(__FILE__) . '/Standard')); + $this->loader = new MUtil_Loader_PluginLoader($dirs); + $this->loader->addPrefixPath('', dirname(__FILE__) . '/Standard'); } /** - * Add a directory to the front of the list of places where snippets are loaded from. + * Add prefixed paths to the registry of paths * - * @param string $dir - * @return MUtil_Snippets_SnippetLoader + * @param string $prefix + * @param string $path + * @return MUtil_Snippets_SnippetLoaderInterface */ - public function addDirectory($dir) + public function addPrefixPath($prefix, $path) { - if (! in_array($dir, $this->snippetsDirectories)) { - if (file_exists($dir)) { - array_unshift($this->snippetsDirectories, $dir); - } - } + $this->loader->addPrefixPath($prefix, $path); return $this; } /** - * Add parameter values to the source for snippets. - * - * @param mixed $container_or_pairs This function can be called with either a single container or a list of name/value pairs. - * @return MUtil_Snippets_SnippetLoader - */ - public function addSource($container_or_pairs) - { - if (1 == func_num_args()) { - $container = $container_or_pairs; - } else { - $container = MUtil_Ra::pairs(func_get_args()); - } - - $source = $this->getSnippetsSource(); - $source->addRegistryContainer($container); - - return $this; - } - - /** - * Returns the directories where snippets are loaded from. - * - * @param array $dirs - * @return array - */ - public function getDirectories() - { - return $this->snippetsDirectories; - } - - /** * Searches and loads a .php snippet file. * - * @param string $filename The name of the snippet + * @param string $className The name of the snippet * @param array $extraSourceParameters name/value pairs to add to the source for this snippet * @return MUtil_Snippets_SnippetInterface The snippet */ - public function getSnippet($filename, array $extraSourceParameters = null) + public function getSnippet($className, array $extraSourceParameters = null) { - $source = $this->getSource(); + $className = $this->loader->load($className); - // Add extra parameters when specified - if ($extraSourceParameters) { - $extraSourceName = __CLASS__ . '->' . __FUNCTION__; - $source->addRegistryContainer($extraSourceParameters, $extraSourceName); - } + $snippet = new $className(); - $dirs = $this->getDirectories(); + if ($snippet instanceof MUtil_Snippets_SnippetInterface) { + // Add extra parameters when specified + if ($extraSourceParameters) { + $this->snippetsSource->addRegistryContainer($extraSourceParameters, 'tmpContainer'); + } - $classname = $filename; - if (strpos($filename, '_') === false) { - $filename = $filename . '.php'; - } else { - $filename = str_replace('_', '/', $filename) . '.php'; - } + if ($this->snippetsSource->applySource($snippet)) { + if ($extraSourceParameters) { + // Can remove now, it was applied + $this->snippetsSource->removeRegistryContainer('tmpContainer'); + } - foreach ($dirs as $dir) { - $filepath = $dir . '/' . $filename; + return $snippet; - // MUtil_Echo::r($filepath); - if (file_exists($filepath)) { - require_once($filepath); - - $snippet = new $classname(); - - if ($snippet instanceof MUtil_Snippets_SnippetInterface) { - if ($source->applySource($snippet)) { - if ($extraSourceParameters) { - // Can remove now, it was applied - $source->removeRegistryContainer($extraSourceName); - } - - return $snippet; - - } else { - throw new Zend_Exception("Not all parameters set for html snippet: '$filepath'. \n\nRequested variables were: " . implode(", ", $snippet->getRegistryRequests())); - } - } else { - throw new Zend_Exception("The snippet: '$filepath' does not implement the MUtil_Snippets_SnippetInterface interface."); - } + } else { + throw new Zend_Exception("Not all parameters set for html snippet: '$className'. \n\nRequested variables were: " . implode(", ", $snippet->getRegistryRequests())); } + } else { + throw new Zend_Exception("The snippet: '$className' does not implement the MUtil_Snippets_SnippetInterface interface."); } - - throw new Zend_Exception("Call for non existing html snippet: '$filename'. \n\nLooking in directories: " . implode(", ", $dirs)); } /** @@ -192,14 +145,15 @@ } /** - * Set the directories where snippets are loaded from. + * Remove a prefix (or prefixed-path) from the registry * - * @param array $dirs - * @return MUtil_Snippets_SnippetLoader (continuation pattern) + * @param string $prefix + * @param string $path OPTIONAL + * @return MUtil_Snippets_SnippetLoaderInterface */ - public function setDirectories(array $dirs) + public function removePrefixPath($prefix, $path = null) { - $this->snippetsDirectories = array_reverse($dirs); + $this->loader->removePrefixPath($prefix, $path); return $this; } Modified: trunk/library/classes/MUtil/Snippets/SnippetLoaderInterface.php =================================================================== --- trunk/library/classes/MUtil/Snippets/SnippetLoaderInterface.php 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/classes/MUtil/Snippets/SnippetLoaderInterface.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -2,7 +2,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 @@ -13,7 +13,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 @@ -47,41 +47,27 @@ * Sets the source of variables and the first directory for snippets * * @param mixed $source Something that is or can be made into MUtil_Registry_SourceInterface, otheriwse Zend_Registry is used. + * @param array $dirs prefix => pathname The inital paths to load from */ - public function __construct($source = null); + public function __construct($source = null, array $dirs = array()); /** - * Add a directory to the front of the list of places where snippets are loaded from. + * Add prefixed paths to the registry of paths * - * @param string $dir + * @param string $prefix + * @param string $path * @return MUtil_Snippets_SnippetLoaderInterface */ - public function addDirectory($dir); + public function addPrefixPath($prefix, $path); /** - * Add parameter values to the source for snippets. - * - * @param mixed $container_or_pairs This function can be called with either a single container or a list of name/value pairs. - * @return MUtil_Snippets_SnippetLoaderInterface - */ - public function addSource($container_or_pairs); - - /** - * Returns the directories where snippets are loaded from. - * - * @param array $dirs - * @return array - */ - public function getDirectories(); - - /** * Searches and loads a .php snippet file. * - * @param string $filename The name of the snippet + * @param string $className The name of the snippet * @param array $extraSourceParameters name/value pairs to add to the source for this snippet * @return MUtil_Snippets_SnippetInterface The snippet */ - public function getSnippet($filename, array $extraSourceParameters = null); + public function getSnippet($className, array $extraSourceParameters = null); /** * Returns a source of values for snippets. @@ -91,18 +77,19 @@ public function getSource(); /** - * Set the directories where snippets are loaded from. + * Remove a prefix (or prefixed-path) from the registry * - * @param array $dirs - * @return MUtil_Snippets_SnippetLoaderInterface (continuation pattern) + * @param string $prefix + * @param string $path OPTIONAL + * @return MUtil_Snippets_SnippetLoaderInterface */ - public function setDirectories(array $dirs); + public function removePrefixPath($prefix, $path = null); /** * Sets the source of variables for snippets * * @param MUtil_Registry_SourceInterface $source - * @return MUtil_Snippets_SnippetLoaderInterface (continuation pattern) + * @return MUtil_Snippets_SnippetLoader (continuation pattern) */ public function setSource(MUtil_Registry_SourceInterface $source); } \ No newline at end of file Modified: trunk/library/classes/ZFDebug/Controller/Plugin/Debug.php =================================================================== --- trunk/library/classes/ZFDebug/Controller/Plugin/Debug.php 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/classes/ZFDebug/Controller/Plugin/Debug.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -410,6 +410,11 @@ protected function _headerOutput() { $collapsed = isset($_COOKIE['ZFDebugCollapsed']) ? $_COOKIE['ZFDebugCollapsed'] : 0; + $jquery = MUtil_JQuery::jQuery(); + if ($jquery->useLocalPath()) { + $this->_options['jquery_path'] = $jquery->getLocalPath(); + } + return (' <style type="text/css" media="screen"> #ZFDebug_debug { font: 11px/1.4em Lucida Grande, Lucida Sans Unicode, sans-serif; position:fixed; bottom:5px; left:5px; color:#000; z-index: ' . $this->_options['z-index'] . ';} Modified: trunk/library/pre_bootstrap.php =================================================================== --- trunk/library/pre_bootstrap.php 2013-01-09 17:30:52 UTC (rev 1091) +++ trunk/library/pre_bootstrap.php 2013-01-10 16:43:36 UTC (rev 1092) @@ -59,25 +59,16 @@ APPLICATION_PATH . '/classes' . PATH_SEPARATOR . GEMS_LIBRARY_DIR . '/classes' . PATH_SEPARATOR . get_include_path() - //. PATH_SEPARATOR . GEMS_ROOT_DIR . '/library' //Shouldn't be needed, uncomment when neccessary ); -$GEMS_DIRS = array( - GEMS_PROJECT_NAME_UC => APPLICATION_PATH . '/classes', - 'Gems' => GEMS_LIBRARY_DIR . '/classes' -); - -// Set up autoload +// Set up autoload for MUtil require_once 'Zend/Loader/AutoLoader.php'; -$autoloader = Zend_Loader_Autoloader::getInstance(); +$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')); +// $cachedloader = MUtil_Loader_CachedLoader::getInstance(GEMS_ROOT_DIR . '/var/cache'); +// $autoloader->setDefaultAutoloader(array($cachedloader, 'autoload')); // Create application, bootstrap, and run $application = new Zend_Application( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |