From: <gem...@li...> - 2013-01-11 18:14:28
|
Revision: 1096 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1096&view=rev Author: matijsdejong Date: 2013-01-11 18:14:20 +0000 (Fri, 11 Jan 2013) Log Message: ----------- Continuing on the method to format values Modified Paths: -------------- trunk/library/classes/MUtil/Loader/PluginLoader.php trunk/library/classes/MUtil/Model/ModelAbstract.php trunk/library/classes/MUtil/Model.php Modified: trunk/library/classes/MUtil/Loader/PluginLoader.php =================================================================== --- trunk/library/classes/MUtil/Loader/PluginLoader.php 2013-01-11 15:24:03 UTC (rev 1095) +++ trunk/library/classes/MUtil/Loader/PluginLoader.php 2013-01-11 18:14:20 UTC (rev 1096) @@ -47,11 +47,23 @@ class MUtil_Loader_PluginLoader extends Zend_Loader_PluginLoader { /** + * Add the default autoloader to this plugin loader. + * + * @return Zend_Loader_PluginLoader (continuation pattern) + */ + public function addFallBackPath() + { + parent::addPrefixPath('', ''); + + return $this; + } + + /** * Add prefixed paths to the registry of paths * * @param string $prefix * @param string $path - * @return Zend_Loader_PluginLoader + * @return Zend_Loader_PluginLoader (continuation pattern) */ public function addPrefixPath($prefix, $path) { @@ -66,6 +78,7 @@ return $this; } + /** * Instantiate a new class using the arguments array for initiation * @@ -75,7 +88,7 @@ */ public function createClass($className, array $arguments = array()) { - if (!class_exists($className)) { + if (!class_exists($className, false)) { $className = $this->load($className); } Modified: trunk/library/classes/MUtil/Model/ModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/ModelAbstract.php 2013-01-11 15:24:03 UTC (rev 1095) +++ trunk/library/classes/MUtil/Model/ModelAbstract.php 2013-01-11 18:14:20 UTC (rev 1096) @@ -67,10 +67,46 @@ private $_changedCount = 0; private $_keys; + + /** + * Contains the per field settings of the model + * + * @var array field_name => array(settings) + */ private $_model = array(); - private $_model_meta; + + /** + * Contains the settings for the model as a whole + * + * @var array + */ + private $_model_meta = array( + MUtil_Model::META_ASSEMBLERS => array( + MUtil_Model::FORM => 'FormAssembler', + ), + ); + + /** + * An identifying name for the model + * + * @var string + */ private $_model_name; + + /** + * The order in which field names where ->set() since + * the last ->resetOrder() - minus those not set. + * + * @var array + */ private $_model_order; + + /** + * Contains the (order in which) fields where accessed using + * ->get(), containing only those fields that where accesed. + * + * @var type + */ private $_model_used = false; /** @@ -509,6 +545,12 @@ } } + /** + * Returns the field that name is an Alias of + * + * @param string $name + * @return string + */ public function getAlias($name) { if (isset($this->_model[$name][self::ALIAS_OF])) { @@ -516,6 +558,42 @@ } } + /** + * Get/load the assembler for the specific idenitifier + * + * @param string $identifier + * @param array $data Optional array with data. + * @return MUtil_Model_AssemblerInterface + */ + public function getAssemblerFor($identifier, array $data = null) + { + $assemblers = $this->getMeta(MUtil_Model::META_ASSEMBLERS); + + if (isset($assemblers[$identifier])) { + if ($assemblers[$identifier] instanceof MUtil_Model_AssemblerInterface) { + return $assemblers[$identifier]; + } + + $loader = MUtil_Model::getAssemblerLoader(); + $assembler = $loader->createClass($assemblers[$identifier]); + $assembler->setModel($this); + + if (null !== $data) { + $assembler->setRow($data); + } + + $assemblers[$identifier] = $assembler; + $this->setMeta(MUtil_Model::META_ASSEMBLERS, $assemblers); + + return $assembler; + } + } + + /** + * The number of item rows changed since the last save or delete + * + * @return int + */ public function getChanged() { return $this->_changedCount; @@ -546,11 +624,30 @@ return $results; } + /** + * Get the current default filter for save/loade + * @return array + */ public function getFilter() { return $this->getMeta('filter', array()); } + /** + * Get/load the assembler for forms + * + * @param array $data Optional array with data. + * @return MUtil_Model_AssemblerInterface + */ + public function getFormAssembler(array $data = null) + { + return $this->getAssemblerFor(MUtil_Model::FORM, $data); + } + + /** + * Returns all the field names in this model + * @return array + */ public function getItemNames() { return array_keys($this->_model); Modified: trunk/library/classes/MUtil/Model.php =================================================================== --- trunk/library/classes/MUtil/Model.php 2013-01-11 15:24:03 UTC (rev 1095) +++ trunk/library/classes/MUtil/Model.php 2013-01-11 18:14:20 UTC (rev 1096) @@ -37,6 +37,16 @@ class MUtil_Model { /** + * Indentifier for form (meta) assemblers and (field) processors + */ + const FORM = 'form'; + + /** + * Indentifier for assemblers meta key + */ + const META_ASSEMBLERS = 'assemblers'; + + /** * In order to keep the url's short and to hide any field names from * the user, model identifies key values by using 'id' for a single * key value and id1, id2, etc... for multiple keys. @@ -86,6 +96,12 @@ const TYPE_TIME = 5; /** + * + * @var MUtil_Loader_PluginLoader + */ + private static $_assemblerLoader; + + /** * Static variable for debuggging purposes. Toggles the echoing of e.g. of sql * select statements, using MUtil_Echo. * @@ -100,4 +116,34 @@ * @var boolean $verbose If true echo retrieval statements. */ public static $verbose = false; + + /** + * Returns the plugin loader for assemblers + * + * @return MUtil_Loader_PluginLoader + */ + public static function getAssemblerLoader() + { + if (! self::$_assemblerLoader) { + $loader = new MUtil_Loader_PluginLoader(); + + $loader->addPrefixPath('MUtil_Model_Assembler', __DIR__ . '/Model/Assembler') + ->addFallBackPath(); + // maybe add interface def to plugin loader: MUtil_Model_AssemblerInterface + + self::$_assemblerLoader = $loader; + } + + return self::$_assemblerLoader; + } + + /** + * Sets the plugin loader for assemblers + * + * @param MUtil_Loader_PluginLoader $loader + */ + public static function setAssemblerLoader(MUtil_Loader_PluginLoader $loader) + { + self::$_assemblerLoader = $loader; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |