From: <gem...@li...> - 2013-01-13 20:03:25
|
Revision: 1098 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1098&view=rev Author: matijsdejong Date: 2013-01-13 20:03:13 +0000 (Sun, 13 Jan 2013) Log Message: ----------- Loader/PluginLoader.php now checks the include path for possible loading directories Assemblers and Processors can be loaded through (centrally defined) plugin Loader/PluginLoader.php Model/Input loads options lazily Model/AssemblerInterface allows options to be set during processor construction Modified Paths: -------------- trunk/library/classes/MUtil/Loader/PluginLoader.php trunk/library/classes/MUtil/Model/Assembler/FormAssembler.php trunk/library/classes/MUtil/Model/AssemblerAbstract.php trunk/library/classes/MUtil/Model/AssemblerInterface.php trunk/library/classes/MUtil/Model/Input.php trunk/library/classes/MUtil/Model/ModelAbstract.php trunk/library/classes/MUtil/Model/Processor/ElementProcessorAbstract.php trunk/library/classes/MUtil/Model.php Added Paths: ----------- trunk/library/classes/MUtil/Model/Processor/Element/SelectElementProcessor.php Modified: trunk/library/classes/MUtil/Loader/PluginLoader.php =================================================================== --- trunk/library/classes/MUtil/Loader/PluginLoader.php 2013-01-11 18:28:58 UTC (rev 1097) +++ trunk/library/classes/MUtil/Loader/PluginLoader.php 2013-01-13 20:03:13 UTC (rev 1098) @@ -71,15 +71,10 @@ throw new Zend_Loader_PluginLoader_Exception('Zend_Loader_PluginLoader::addPrefixPath() method only takes strings for prefix and path.'); } - if ($path) { - if (('/' == $path[0]) || ('.' == $path[0]) || ((strlen($path) > 1) && (':' == $path[1]))) { - // Only add existing directories - if (! file_exists(rtrim($path, '/\\'))) { - return $this; - } - } + // MUtil_Echo::track(self::getAbsolutePaths($path)); + foreach (self::getAbsolutePaths($path) as $sub) { + parent::addPrefixPath($prefix, $sub); } - parent::addPrefixPath($prefix, $path); return $this; } @@ -163,4 +158,81 @@ ); } } + + /** + * Add existing include path directories to subdirectory (if not absolute) + * + * @staticvar string $includePaths Array containing exploded and checked include path + * @param string $path + * @return array Can be empty if none of the options exist + */ + public static function getAbsolutePaths($path) + { + static $includePaths; + + if ($path) { + // Try to see if the path is an absolute path. Some exotic absolute paths can fail this test, + // but it is more error prone to test for them here than to loop through them afterwards. + if (self::isAbsolutePath($path)) { + if ($real = realpath($path)) { + return array($real); + } else { + return array(); + } + } + } + + if (! is_array($includePaths)) { + // Make sure the include path are loaded + foreach (Zend_Loader::explodeIncludePath() as $include) { + // Current path will be checked, for each file + // but check the other paths for exiistence + if (('.' != $include) && ($real = realpath($include))) { + $includePaths[] = $real . DIRECTORY_SEPARATOR; + } + } + } + + // Check path name + $results = array(); + if ($real = realpath($path)) { + $results[] = $real; + } + + // Check simple concatenation + foreach ($includePaths as $include) { + if ($real = realpath($include . $path)) { + $results[] = $real;; + } + } + + // Reverse the result as that is the order this loader handles the directories + return array_reverse($results); + } + + /** + * Do a quick check for a path being absolute (may not work for some exotic absolute paths though) + * + * @param string $path + * @return boolean + */ + public static function isAbsolutePath($path) + { + if ($path) { + // Try to see if the path is an absolute path. Some exotic absolute paths can fail this test, + // but it is more error prone to test for them here than to loop through them afterwards. + if (substr(PHP_OS, 0, 1) === 'WIN') { + // Match for A:\ and \\ network paths + if (preg_match('/([A-Za-z]:\\|\\\\)./', $path)) { + return true; + } + } else { + if (strlen($path) && (DIRECTORY_SEPARATOR === $path[0])) { + return true; + } + } + } + + return false; + } } Modified: trunk/library/classes/MUtil/Model/Assembler/FormAssembler.php =================================================================== --- trunk/library/classes/MUtil/Model/Assembler/FormAssembler.php 2013-01-11 18:28:58 UTC (rev 1097) +++ trunk/library/classes/MUtil/Model/Assembler/FormAssembler.php 2013-01-13 20:03:13 UTC (rev 1098) @@ -49,12 +49,18 @@ /** * Create the processor for this name * + * @param MUtil_Model_ModelAbstract $model * @param string $name - * @return MUtil_Model_ProcessorInterface or null when it does not exist + * @return MUtil_Model_ProcessorInterface or string or array for creation null when it does not exist */ - protected function _assemble($name) + protected function _assemble(MUtil_Model_ModelAbstract $model, $name) { - return new MUtil_Model_Processor_Element_TextElementProcessor(); + + if ($model->has($name, 'multiOptions')) { + return 'Element_SelectElementProcessor'; + } + + return 'Element_TextElementProcessor'; } } Modified: trunk/library/classes/MUtil/Model/AssemblerAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/AssemblerAbstract.php 2013-01-11 18:28:58 UTC (rev 1097) +++ trunk/library/classes/MUtil/Model/AssemblerAbstract.php 2013-01-13 20:03:13 UTC (rev 1098) @@ -36,8 +36,14 @@ */ /** + * Abstract implementation of AssemblerInterface, only _assmble() needs to be + * implemented. * + * This abstract class contains helper functions to facilitate working + * with processors. * + * @see MUtil_Model_AssemblerInterface + * * @package MUtil * @subpackage Model * @copyright Copyright (c) 2012 Erasmus MC @@ -54,12 +60,24 @@ /** * + * @var array name => extra options for name + */ + protected $_extraArgs = array(); + + /** + * * @var MUtil_Model_ModelAbstract */ protected $_model; /** * + * @var MUtil_Loader_PluginLoader + */ + private $_processorLoader = array(); + + /** + * * @var array Of name => MUtil_Model_ProcessorInterface */ protected $_processors = array(); @@ -79,21 +97,37 @@ /** * Create the processor for this name * + * @param MUtil_Model_ModelAbstract $model * @param string $name - * @return MUtil_Model_ProcessorInterface or null when it does not exist + * @return MUtil_Model_ProcessorInterface or string or array for creation null when it does not exist */ - abstract protected function _assemble($name); + abstract protected function _assemble(MUtil_Model_ModelAbstract $model, $name); /** * Get the processed output of the input or a lazy object if the data is repeated * or not yet set using setRepeater() or setRow(). * * @param string $name + * @param mixed $arrayOrKey1 A key => value array or the name of the first key, see MUtil_Args::pairs() + * These setting are applied to the model. + * @param mixed $value1 The value for $arrayOrKey1 or null when $arrayOrKey1 is an array + * @param string $key2 Optional second key when $arrayOrKey1 is a string + * @param mixed $value2 Optional second value when $arrayOrKey1 is a string, + * an unlimited number of $key values pairs can be given. * @return mixed MUtil_Lazy_Call when not using setRow(), actual output otherwise */ - public function getOutput($name) + public function getOutput($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null) { - if (! $this->hasProcessor($name)) { + // Process new settings + if ($args = MUtil_Ra::pairs(func_get_args(), 1)) { + if (! $this->_model) { + throw new MUtil_Model_ModelException("Cannot use processor without a model."); + } + + $this->_model->set($name, $args); + } + + if (! $this->hasProcessor($name, $args)) { if ($this->_row) { if (isset($this->_row[$name])) { return $this->_row[$name]; @@ -119,14 +153,44 @@ return new MUtil_Lazy_Call(array($this, 'output'), array($name)); } + /** + * Returns the plugin loader for processors. + * + * @return MUtil_Loader_PluginLoader + */ + public function getProcessorLoader() + { + if (! $this->_processorLoader) { + $this->setProcessorLoader(MUtil_Model::getProcessorLoader()); + } + + return $this->_processorLoader; + } + + /** * Returns the processor for the name * * @param string $name + * @param mixed $arrayOrKey1 A key => value array or the name of the first key, see MUtil_Args::pairs() + * These setting are applied to the model. + * @param mixed $value1 The value for $arrayOrKey1 or null when $arrayOrKey1 is an array + * @param string $key2 Optional second key when $arrayOrKey1 is a string + * @param mixed $value2 Optional second value when $arrayOrKey1 is a string, + * an unlimited number of $key values pairs can be given. * @return MUtil_Model_ProcessorInterface or null when it does not exist */ - public function getProcessor($name) + public function getProcessor($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null) { + // Process new settings + if ($args = MUtil_Ra::pairs(func_get_args(), 1)) { + if (! $this->_model) { + throw new MUtil_Model_ModelException("Cannot use processor without a model."); + } + + $this->_model->set($name, $args); + } + if ($this->hasProcessor($name)) { return $this->_processors[$name]; } @@ -140,13 +204,17 @@ */ public function hasProcessor($name) { + if (! $this->_model) { + throw new MUtil_Model_ModelException("Cannot use processor without a model."); + } + if (! array_key_exists($name, $this->_processors)) { // Default if nothing there $this->_processors[$name] = false; // Try to create one if ($this->_model->has($name)) { - if ($processor = $this->_assemble($name)) { + if ($processor = $this->_assemble($this->_model, $name)) { $this->setProcessor($name, $processor); } } @@ -185,30 +253,57 @@ } /** - * Set the processor for a name + * Set the model of this assembler * - * @param string $name - * $param MUtil_Model_ProcessorInterface $processor + * @param MUtil_Model_ModelAbstract $model * @return MUtil_Model_AssemblerInterface (continuation pattern) */ - public function setProcessor($name, MUtil_Model_ProcessorInterface $processor) + public function setModel(MUtil_Model_ModelAbstract $model) { - $this->_processors[$name] = $processor; + $this->_model = $model; return $this; } /** - * Set the model of this assembler + * Sets the plugin loader for processors. * - * @param MUtil_Model_ModelAbstract $model + * @param MUtil_Loader_PluginLoader $loader + */ + public function setProcessorLoader(MUtil_Loader_PluginLoader $loader) + { + $this->_processorLoader = $loader; + } + + /** + * Set the processor for a name + * + * @param string $name + * $param mixed $processor MUtil_Model_ProcessorInterface or string or array that can be used to create processor * @return MUtil_Model_AssemblerInterface (continuation pattern) */ - public function setModel(MUtil_Model_ModelAbstract $model) + public function setProcessor($name, $processor) { - $this->_model = $model; + if (is_string($processor)) { + $loader = $this->getProcessorLoader(); + $processor = $loader->createClass($processor); - return $this; + } elseif (is_array($processor)) { + $loader = $this->getProcessorLoader(); + $arguments = $processor; + $processor = array_shift($arguments); + + $processor = $loader->createClass($processor, $arguments); + + } + + if ($processor instanceof MUtil_Model_ProcessorInterface) { + $this->_processors[$name] = $processor; + + return $this; + } + + throw new MUtil_Model_ModelException("No valid processor set for '$name'."); } /** Modified: trunk/library/classes/MUtil/Model/AssemblerInterface.php =================================================================== --- trunk/library/classes/MUtil/Model/AssemblerInterface.php 2013-01-11 18:28:58 UTC (rev 1097) +++ trunk/library/classes/MUtil/Model/AssemblerInterface.php 2013-01-13 20:03:13 UTC (rev 1098) @@ -36,7 +36,12 @@ */ /** + * An assembler creates Processors that generate output for fieldnames. * + * The processer for a field (accessed through getProcessor()) does not depend + * on the specific current row data, but the output of that processor + * (accesible through getOutput()) can change depending on the content + * of the row data. * * @package MUtil * @subpackage Model @@ -51,17 +56,29 @@ * or not yet set using setRepeater() or setRow(). * * @param string $name + * @param mixed $arrayOrKey1 A key => value array or the name of the first key, see MUtil_Args::pairs() + * These setting are applied to the model. + * @param mixed $value1 The value for $arrayOrKey1 or null when $arrayOrKey1 is an array + * @param string $key2 Optional second key when $arrayOrKey1 is a string + * @param mixed $value2 Optional second value when $arrayOrKey1 is a string, + * an unlimited number of $key values pairs can be given. * @return mixed MUtil_Lazy_Call when not using setRow(), actual output otherwise */ - public function getOutput($name); + public function getOutput($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null); /** * Returns the processor for the name * * @param string $name + * @param mixed $arrayOrKey1 A key => value array or the name of the first key, see MUtil_Args::pairs() + * These setting are applied to the model. + * @param mixed $value1 The value for $arrayOrKey1 or null when $arrayOrKey1 is an array + * @param string $key2 Optional second key when $arrayOrKey1 is a string + * @param mixed $value2 Optional second value when $arrayOrKey1 is a string, + * an unlimited number of $key values pairs can be given. * @return MUtil_Model_ProcessorInterface or null when it does not exist */ - public function getProcessor($name); + public function getProcessor($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null); /** * Returns true if a processor exist for $name @@ -83,10 +100,10 @@ * Set the processor for a name * * @param string $name - * $param MUtil_Model_ProcessorInterface $processor + * $param mixed $processor MUtil_Model_ProcessorInterface or string or array that can be used to create processor * @return MUtil_Model_AssemblerInterface (continuation pattern) */ - public function setProcessor($name, MUtil_Model_ProcessorInterface $processor); + public function setProcessor($name, $processor); /** * Use this method when you want to repeat the output for each row when rendering. Modified: trunk/library/classes/MUtil/Model/Input.php =================================================================== --- trunk/library/classes/MUtil/Model/Input.php 2013-01-11 18:28:58 UTC (rev 1097) +++ trunk/library/classes/MUtil/Model/Input.php 2013-01-13 20:03:13 UTC (rev 1098) @@ -70,7 +70,7 @@ * * @var array */ - protected $_options; + protected $_options = array(); /** * The original begin value @@ -102,7 +102,6 @@ $this->_context = $context; $this->_model = $model; $this->_name = $name; - $this->_options = $model->get($name); $this->_origValue = $context[$name]; $this->_output = $this->_origValue; } @@ -144,17 +143,29 @@ { if (array_key_exists($name, $this->_options)) { return $this->_options[$name]; + } else { + return $this->_model->get($this->_name, $name); } } /** - * Return all options + * Return all or a named subset of options * + * @param array $names Optional: an array of names to get the options from * @return array */ - public function getOptions() + public function getOptions(array $names = null) { - return $this->_options; + if (null === $names) { + // Return all + return $this->_options + $this->_model->get($this->_name); + } + + $result = array(); + foreach ($names as $name) { + $result[$name] = $this->getOption($name); + } + return $result; } /** @@ -206,6 +217,11 @@ { // If $key end with ] it is array value if (substr($name, -1) == ']') { + // Load from original model + if (! isset($this->_options[$name])) { + $this->_options[$name] = $this->_model->get($this->_name, $name); + } + if (substr($name, -2) == '[]') { // If $name ends with [], append it to array $name = substr($name, 0, -2); Modified: trunk/library/classes/MUtil/Model/ModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/ModelAbstract.php 2013-01-11 18:28:58 UTC (rev 1097) +++ trunk/library/classes/MUtil/Model/ModelAbstract.php 2013-01-13 20:03:13 UTC (rev 1098) @@ -569,24 +569,27 @@ { $assemblers = $this->getMeta(MUtil_Model::META_ASSEMBLERS); - if (isset($assemblers[$identifier])) { - if ($assemblers[$identifier] instanceof MUtil_Model_AssemblerInterface) { - return $assemblers[$identifier]; - } + if (! isset($assemblers[$identifier])) { + // We cannot create when noting is specified + return null; + } - $loader = MUtil_Model::getAssemblerLoader(); - $assembler = $loader->createClass($assemblers[$identifier]); - $assembler->setModel($this); + if ($assemblers[$identifier] instanceof MUtil_Model_AssemblerInterface) { + return $assemblers[$identifier]; + } - if (null !== $data) { - $assembler->setRow($data); - } + $loader = MUtil_Model::getAssemblerLoader(); + $assembler = $loader->createClass($assemblers[$identifier]); + $assembler->setModel($this); - $assemblers[$identifier] = $assembler; - $this->setMeta(MUtil_Model::META_ASSEMBLERS, $assemblers); + if (null !== $data) { + $assembler->setRow($data); + } - return $assembler; - } + $assemblers[$identifier] = $assembler; + $this->setMeta(MUtil_Model::META_ASSEMBLERS, $assemblers); + + return $assembler; } /** @@ -1165,10 +1168,11 @@ * Both set the attribute 'save' to true for 'field_x'. * * @param string $name The fieldname - * @param string|array $arrayOrKey1 A key => value array or the name of the first key - * @param mixed $value1 The value for $arrayOrKey1 or null when $arrayOrKey1 is an array - * @param string $key2 Optional second key when $arrayOrKey1 is a string - * @param mixed $value2 Optional second value when $arrayOrKey1 is a string, an unlimited number of $key values pairs can be given. + * @param mixed $arrayOrKey1 A key => value array or the name of the first key, see MUtil_Args::pairs() + * @param mixed $value1 The value for $arrayOrKey1 or null when $arrayOrKey1 is an array + * @param string $key2 Optional second key when $arrayOrKey1 is a string + * @param mixed $value2 Optional second value when $arrayOrKey1 is a string, + * an unlimited number of $key values pairs can be given. * @return $this */ public function set($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null) Added: trunk/library/classes/MUtil/Model/Processor/Element/SelectElementProcessor.php =================================================================== --- trunk/library/classes/MUtil/Model/Processor/Element/SelectElementProcessor.php (rev 0) +++ trunk/library/classes/MUtil/Model/Processor/Element/SelectElementProcessor.php 2013-01-13 20:03:13 UTC (rev 1098) @@ -0,0 +1,74 @@ +<?php + +/** + * Copyright (c) 2012, 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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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 Model + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @version $id: DateProcessor.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * + * + * @package MUtil + * @subpackage Model + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since MUtil version 1.2 + */ +class MUtil_Model_Processor_Element_SelectElementProcessor extends MUtil_Model_Processor_ElementProcessorAbstract +{ + /** + * Allow use of answers select specific options + * + * @var boolean + */ + protected $useMultiOptions = true; + + /** + * Processes the input, changing e.g. the result, context or options + * + * @param MUtil_Model_Input $input + * @return void + */ + public function process(MUtil_Model_Input $input) + { + $options = $this->getFilteredOptions($input); + + // Is sometimes added automatically, but should not be used here + unset($options['maxlength']); + + $this->applyElement( + $input, + new Zend_Form_Element_Select($input->getName(), $options) + ); + } +} Modified: trunk/library/classes/MUtil/Model/Processor/ElementProcessorAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/Processor/ElementProcessorAbstract.php 2013-01-11 18:28:58 UTC (rev 1097) +++ trunk/library/classes/MUtil/Model/Processor/ElementProcessorAbstract.php 2013-01-13 20:03:13 UTC (rev 1098) @@ -62,10 +62,17 @@ protected $useDisplayOptions = true; /** - * Allow use textbox specific options + * Allow use of answers select specific options * * @var boolean */ + protected $useMultiOptions = false; + + /** + * Allow use of textbox specific options + * + * @var boolean + */ protected $useTextOptions = false; /** @@ -111,6 +118,18 @@ ); } + if ($this->useMultiOptions) { + $options[] = array( + 'disable', + 'multiOptions', + 'onchange', + 'separator', + 'size', + 'disableTranslator' + ); + + } + if ($this->useTextOptions) { $options[] = array( 'maxlength', @@ -120,6 +139,7 @@ 'onselect', 'size'); } + /* self::CHECK_OPTIONS => array('checkedValue', 'uncheckedValue'), self::DATE_OPTIONS => array('dateFormat', 'storageFormat'), @@ -127,7 +147,6 @@ self::FILE_OPTIONS => array('accept', 'count', 'destination', 'valueDisabled'), self::GROUP_OPTIONS => array('elements', 'legend', 'separator'), self::JQUERY_OPTIONS => array('jQueryParams'), - self::MULTI_OPTIONS => array('disable', 'multiOptions', 'onchange', 'separator', 'size', 'disableTranslator'), self::PASSWORD_OPTIONS => array('repeatLabel'), self::TAB_OPTIONS => array('value'), self::TEXTAREA_OPTIONS => array('cols', 'rows', 'wrap'), @@ -146,7 +165,7 @@ { $allowedOptions = MUtil_Ra::flatten($this->getAllowedOptionsNames()); - $options = $input->getOptions(); + $options = $input->getOptions($allowedOptions); return array_intersect_key($options, array_flip($allowedOptions)); } Modified: trunk/library/classes/MUtil/Model.php =================================================================== --- trunk/library/classes/MUtil/Model.php 2013-01-11 18:28:58 UTC (rev 1097) +++ trunk/library/classes/MUtil/Model.php 2013-01-13 20:03:13 UTC (rev 1098) @@ -97,11 +97,17 @@ /** * - * @var MUtil_Loader_PluginLoader + * @var array of MUtil_Loader_PluginLoader */ - private static $_assemblerLoader; + private static $_loaders = array(); /** + * + * @var array of global for directory paths + */ + private static $_nameSpaces = array('MUtil'); + + /** * Static variable for debuggging purposes. Toggles the echoing of e.g. of sql * select statements, using MUtil_Echo. * @@ -124,26 +130,72 @@ */ public static function getAssemblerLoader() { - if (! self::$_assemblerLoader) { + return self::getLoader('Assembler'); + // maybe add interface def to plugin loader: MUtil_Model_AssemblerInterface + } + + /** + * Returns a subClass plugin loader + * + * @param string $prefix The prefix to load the loader for. CamelCase and should not contain an '_', '/' or '\'. + * @return MUtil_Loader_PluginLoader + */ + public static function getLoader($subClass) + { + if (! isset(self::$_loaders[$subClass])) { $loader = new MUtil_Loader_PluginLoader(); - $loader->addPrefixPath('MUtil_Model_Assembler', __DIR__ . '/Model/Assembler') - ->addFallBackPath(); - // maybe add interface def to plugin loader: MUtil_Model_AssemblerInterface + foreach (self::$_nameSpaces as $nameSpace) { + $loader->addPrefixPath( + $nameSpace . '_Model_' . $subClass, + $nameSpace . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . $subClass); + } + $loader->addFallBackPath(); - self::$_assemblerLoader = $loader; + self::$_loaders[$subClass] = $loader; } - return self::$_assemblerLoader; + return self::$_loaders[$subClass]; } /** + * Returns the plugin loader for processors. + * + * @return MUtil_Loader_PluginLoader + */ + public static function getProcessorLoader() + { + return self::getLoader('Processor'); + // maybe add interface def to plugin loader: MUtil_Model_AssemblerInterface + } + + /** * Sets the plugin loader for assemblers * * @param MUtil_Loader_PluginLoader $loader */ public static function setAssemblerLoader(MUtil_Loader_PluginLoader $loader) { - self::$_assemblerLoader = $loader; + self::setLoader($loader, 'Assembler'); } + + /** + * Sets the plugin loader for assemblers + * + * @param MUtil_Loader_PluginLoader $loader + */ + public static function setLoader(MUtil_Loader_PluginLoader $loader, $subClass) + { + self::$_loaders[$subClass] = $loader; + } + + /** + * Sets the plugin loader for processors. + * + * @param MUtil_Loader_PluginLoader $loader + */ + public static function setProcessorLoader(MUtil_Loader_PluginLoader $loader) + { + self::setLoader($loader, 'Processor'); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |