From: <gem...@li...> - 2012-12-28 16:16:19
|
Revision: 1076 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1076&view=rev Author: matijsdejong Date: 2012-12-28 16:16:11 +0000 (Fri, 28 Dec 2012) Log Message: ----------- Added/fixed documentation and small bugs Modified Paths: -------------- trunk/library/classes/MUtil/Html/Renderer.php trunk/library/classes/MUtil/Model/TableModel.php trunk/library/classes/MUtil/Util/ClassList.php trunk/library/classes/MUtil/Util/FunctionList.php trunk/library/classes/MUtil/Util/LookupList.php Modified: trunk/library/classes/MUtil/Html/Renderer.php =================================================================== --- trunk/library/classes/MUtil/Html/Renderer.php 2012-12-28 13:55:22 UTC (rev 1075) +++ trunk/library/classes/MUtil/Html/Renderer.php 2012-12-28 16:16:11 UTC (rev 1076) @@ -98,13 +98,13 @@ public function canRender($value) { if (is_object($value)) { - if (method_exists($value, '__toString') || - ($value instanceof MUtil_Lazy_LazyInterface) || - ($value instanceof MUtil_Html_HtmlInterface)) { + if (($value instanceof MUtil_Lazy_LazyInterface) || + ($value instanceof MUtil_Html_HtmlInterface) || + method_exists($value, '__toString')) { return true; } - return $this->_classRenderFunctions->get($content); + return $this->_classRenderFunctions->get($value); } else { if (is_array($value)) { Modified: trunk/library/classes/MUtil/Model/TableModel.php =================================================================== --- trunk/library/classes/MUtil/Model/TableModel.php 2012-12-28 13:55:22 UTC (rev 1075) +++ trunk/library/classes/MUtil/Model/TableModel.php 2012-12-28 16:16:11 UTC (rev 1076) @@ -52,6 +52,11 @@ */ private $_table; + /** + * + * @param Zend_Db_Table_Abstract $table An Zend abstract table or the table name + * @param string $altName An alternative name to use, default is the name of the table itself + */ public function __construct($table, $altName = null) { if ($table instanceof Zend_Db_Table_Abstract) { Modified: trunk/library/classes/MUtil/Util/ClassList.php =================================================================== --- trunk/library/classes/MUtil/Util/ClassList.php 2012-12-28 13:55:22 UTC (rev 1075) +++ trunk/library/classes/MUtil/Util/ClassList.php 2012-12-28 16:16:11 UTC (rev 1076) @@ -1,51 +1,68 @@ <?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 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. - */ - + /** - * - * @author Matijs de Jong - * @since 1.0 - * @version 1.1 - * @package MUtil + * 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 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 Util + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $id: ClassList.php 362 2011-12-15 17:21:17Z matijsdejong $ */ /** - * - * @author Matijs de Jong - * @package MUtil + * Return a value (the kind is up to the user), using either an object + * or a class name as lookup key. + * + * When not finding a direct match, this object checks (first) the parent classes + * and then the interfaces for a match. Search results are then stored in a cache. + * + * @package MUtil * @subpackage Util + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 */ class MUtil_Util_ClassList extends MUtil_Util_LookupList { + /** + * Sub classes known to have a mapping + * + * @var array + */ protected $_subClasses; + + /** + * Classes not found in this lookup list + * + * @var array + */ protected $_notSubClasses; /** @@ -75,56 +92,58 @@ { if (is_object($key)) { $class = get_class($key); + } else { + $class = $key; + } - // Check for existence - if ($result = parent::_getItem($class, $default)) { - return $result; - } - // Check was already found - if (array_key_exists($class, $this->_subClasses)) { - return $this->_subClasses[$class]; - } - // Check was already searched and not found - if (array_key_exists($class, $this->_notSubClasses)) { - return $default; - } + // Check for simple existence + if ($result = parent::_getItem($class, $default)) { + return $result; + } - // Check the parent classes of the object - $parents = class_parents($key); - $result = null; - foreach ($parents as $parentClass) { - if ($result = parent::_getItem($parentClass, null)) { - // Add the current class to the cache - $this->_subClasses[$class] = $result; + // Check was already found + if (array_key_exists($class, $this->_subClasses)) { + return $this->_subClasses[$class]; + } - // Add all parents up to the one matching to the cache - foreach ($parents as $priorParent) { - $this->_subClasses[$priorParent] = $result; - if ($parentClass === $priorParent) { - // Further parents are not automatically in the list - break; - } + // Check was already searched and not found + if (array_key_exists($class, $this->_notSubClasses)) { + return $default; + } + + // Check the parent classes of the object + $parents = class_parents($key); + $result = null; + foreach ($parents as $parentClass) { + if ($result = parent::_getItem($parentClass, null)) { + // Add the current class to the cache + $this->_subClasses[$class] = $result; + + // Add all parents up to the one matching to the cache + foreach ($parents as $priorParent) { + $this->_subClasses[$priorParent] = $result; + if ($parentClass === $priorParent) { + // Further parents are not automatically in the list + break; } - return $result; } + return $result; } + } - // Check the interfaces implemented by the object - $implemented = class_implements($key); - foreach ($implemented as $interface) { - if ($result = parent::_getItem($interface, null)) { - // Add the current class to the cache - $this->_subClasses[$class] = $result; - return $result; - } + // Check the interfaces implemented by the object + $implemented = class_implements($key); + foreach ($implemented as $interface) { + if ($result = parent::_getItem($interface, null)) { + // Add the current class to the cache + $this->_subClasses[$class] = $result; + return $result; } + } - // Add to the not found cache - $this->_notSubClasses[$class] = true; + // Add to the not found cache + $this->_notSubClasses[$class] = true; - return $default; - } else { - return parent::_getItem($key, $default); - } + return $default; } } \ No newline at end of file Modified: trunk/library/classes/MUtil/Util/FunctionList.php =================================================================== --- trunk/library/classes/MUtil/Util/FunctionList.php 2012-12-28 13:55:22 UTC (rev 1075) +++ trunk/library/classes/MUtil/Util/FunctionList.php 2012-12-28 16:16:11 UTC (rev 1076) @@ -1,47 +1,49 @@ <?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 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. - */ - + /** - * - * @author Matijs de Jong - * @since 1.0 - * @version 1.1 - * @package MUtil + * 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 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 Util + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $id: FunctionList.php 362 2011-12-15 17:21:17Z matijsdejong $ */ /** - * - * @author Matijs de Jong - * @package MUtil + * Return a function value using a scalar key. + * + * @package MUtil * @subpackage Util + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 */ class MUtil_Util_FunctionList extends MUtil_Util_LookupList { @@ -59,9 +61,11 @@ if (isset($this->_elements[$key])) { $function = $this->_elements[$key]; - // TODO: Check for object loading here - - return $function; + if (is_callable($function)) { + return $function; + } else { + return $default; + } } else { return $default; } Modified: trunk/library/classes/MUtil/Util/LookupList.php =================================================================== --- trunk/library/classes/MUtil/Util/LookupList.php 2012-12-28 13:55:22 UTC (rev 1075) +++ trunk/library/classes/MUtil/Util/LookupList.php 2012-12-28 16:16:11 UTC (rev 1076) @@ -1,47 +1,52 @@ <?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 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. - */ - + /** - * - * @author Matijs de Jong - * @since 1.0 - * @version 1.1 - * @package MUtil + * 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 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 Util + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $id: LookupList.php 362 2011-12-15 17:21:17Z matijsdejong $ */ /** - * - * @author Matijs de Jong - * @package MUtil + * Return a value (the kind is up to the user) using a scalar key. + * + * The advantages to using e.g. a standard array object is that both the + * key type and the search algorithm can be customized in each child class. + * + * @package MUtil * @subpackage Util + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 */ class MUtil_Util_LookupList { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |