From: <gem...@li...> - 2012-03-30 14:47:04
|
Revision: 587 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=587&view=rev Author: matijsdejong Date: 2012-03-30 14:46:53 +0000 (Fri, 30 Mar 2012) Log Message: ----------- Number not according to standard Added Paths: ----------- tags/1.5.3-pulse-20120303/ Removed Paths: ------------- tags/153-pulse-20120303/ Property changes on: tags/1.5.3-pulse-20120303 ___________________________________________________________________ Added: svn:ignore + nbproject Added: svn:mergeinfo + /branches/1.5.0-pulse:306-430,467 /branches/1.5.x:426-455,458-472,475-481 /tags/1.5.0beta1:305 /tags/1.5.1:485,489,509-510 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2012-12-29 19:32:12
|
Revision: 1078 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1078&view=rev Author: matijsdejong Date: 2012-12-29 19:32:02 +0000 (Sat, 29 Dec 2012) Log Message: ----------- Modified Paths: -------------- tags/MUtil_1.2/Version.php Added Paths: ----------- tags/MUtil_1.2/ tags/MUtil_1.2/Html/Creator.php tags/MUtil_1.2/Html/Renderer.php tags/MUtil_1.2/Model/TableModel.php tags/MUtil_1.2/Util/ClassList.php tags/MUtil_1.2/Util/FunctionList.php tags/MUtil_1.2/Util/LookupList.php Removed Paths: ------------- tags/MUtil_1.2/Html/Creator.php tags/MUtil_1.2/Html/Renderer.php tags/MUtil_1.2/Model/TableModel.php tags/MUtil_1.2/Util/ClassList.php tags/MUtil_1.2/Util/FunctionList.php tags/MUtil_1.2/Util/LookupList.php Property changes on: tags/MUtil_1.2 ___________________________________________________________________ Added: svn:mergeinfo + /branches/1.5.0-pulse/library/classes/MUtil:306-344,346,467 /branches/1.5.x/library/classes/MUtil:426-455,458-472,475-481 /branches/newUser/classes/MUtil:113-150 /branches/newUser2/classes/MUtil:175-207 /branches/receptioncodes/library/classes/MUtil:1053-1054 /branches/userloader/classes/MUtil:259-324 /tags/1.5.0beta1/library/classes/MUtil:305 /tags/1.5.1/library/classes/MUtil:485,489,509-510,534 /tags/1.5.3-rc2/library/classes/MUtil:612,614,616,618 /tags/1.5.6-pulse20121012/library/classes/MUtil:986 Deleted: tags/MUtil_1.2/Html/Creator.php =================================================================== --- trunk/library/classes/MUtil/Html/Creator.php 2012-12-27 14:35:57 UTC (rev 1073) +++ tags/MUtil_1.2/Html/Creator.php 2012-12-29 19:32:02 UTC (rev 1078) @@ -1,236 +0,0 @@ -<?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. - * - * @package MUtil - * @subpackage Html - * @author Matijs de Jong <mj...@ma...> - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @version $id: Creator.php 362 2011-12-15 17:21:17Z matijsdejong $ - */ - -/** - * Class for storing references for creating html attributes, elements and other objects. - * - * Basically this class stores list of element and attributes names that should be treated - * in different from just creating the most basic of element types. - * - * @package MUtil - * @subpackage Html - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @since Class available since version 1.0 - */ - -class MUtil_Html_Creator -{ - /** - * - * @var MUtil_Util_LookupList - */ - protected $_attributeFunctionList; - - /** - * - * @var MUtil_Util_LookupList - */ - protected $_elementFunctionList; - - /** - * - * @var array - */ - protected $_initialAttributeFunctions = array( - 'href' => 'MUtil_Html_HrefArrayAttribute::hrefAttribute', - 'onclick' => 'MUtil_Html_OnClickArrayAttribute::onclickAttribute', - 'src' => 'MUtil_Html_SrcArrayAttribute::srcAttribute', - 'style' => 'MUtil_Html_StyleArrayAttribute::styleAttribute', - ); - - /** - * - * @var array - */ - protected $_initalElementFunctions = array( - 'a' => 'MUtil_Html_AElement::a', - 'array' => 'MUtil_Html_Sequence::createSequence', - 'call' => 'MUtil_Lazy::call', - 'col' => 'MUtil_Html_ColElement::col', - 'colgroup' => 'MUtil_Html_ColGroupElement::colgroup', - 'dir' => 'MUtil_Html_ListElement::dir', - 'dd' => 'MUtil_Html_DdElement::dd', - 'dl' => 'MUtil_Html_DlElement::dl', - 'dt' => 'MUtil_Html_DtElement::dt', - 'echo' => 'MUtil_Html_TableElement::createVar', - 'email' => 'MUtil_Html_AElement::email', - 'h1' => 'MUtil_Html_HnElement::h1', - 'h2' => 'MUtil_Html_HnElement::h2', - 'h3' => 'MUtil_Html_HnElement::h3', - 'h4' => 'MUtil_Html_HnElement::h4', - 'h5' => 'MUtil_Html_HnElement::h5', - 'h6' => 'MUtil_Html_HnElement::h6', - 'if' => 'MUtil_Lazy::iff', - 'iflink' => 'MUtil_Html_AElement::iflink', - 'ifmail' => 'MUtil_Html_AElement::ifmail', - 'iframe' => 'MUtil_Html_IFrameElement::iFrame', - 'img' => 'MUtil_Html_ImgElement::img', - 'image' => 'MUtil_Html_ImgElement::img', - 'input' => 'MUtil_Html_InputRenderer::input', - 'inputComplete' => 'MUtil_Html_InputRenderer::inputComplete', - 'inputDescription' => 'MUtil_Html_InputRenderer::inputDescription', - 'inputDisplayGroup' => 'MUtil_Html_InputRenderer::inputDisplayGroup', - 'inputElement' => 'MUtil_Html_InputRenderer::inputElement', - 'inputErrors' => 'MUtil_Html_InputRenderer::inputErrors', - 'inputExcept' => 'MUtil_Html_InputRenderer::inputExcept', - 'inputForm' => 'MUtil_Html_InputRenderer::inputForm', - 'inputLabel' => 'MUtil_Html_LabelElement::label', - 'inputOnly' => 'MUtil_Html_InputRenderer::inputOnly', - 'inputOnlyArray' => 'MUtil_Html_InputRenderer::inputOnlyArray', - 'inputUntil' => 'MUtil_Html_InputRenderer::inputUntil', - 'inputUpto' => 'MUtil_Html_InputRenderer::inputUpto', - 'label' => 'MUtil_Html_LabelElement::label', - 'menu' => 'MUtil_Html_ListElement::menu', - 'ol' => 'MUtil_Html_ListElement::ol', - 'pagePanel' => 'MUtil_Html_PagePanel::pagePanel', - 'pForm' => 'MUtil_Html_PFormElement::pForm', - 'progress' => 'MUtil_Html_ProgressPanel::progress', - 'progressPanel' => 'MUtil_Html_ProgressPanel::progress', - 'raw' => 'MUtil_Html_Raw::raw', - 'seq' => 'MUtil_Html_Sequence::createSequence', - 'sequence' => 'MUtil_Html_Sequence::createSequence', // A sequence can contain another sequence, so other function name used - 'snippet' => 'MUtil_Html::snippet', - 'spaced' => 'MUtil_Html_Sequence::createSpaced', // A sequence can contain another sequence, so other function name used - 'table' => 'MUtil_Html_TableElement::table', - 'tbody' => 'MUtil_Html_TBodyElement::tbody', - 'tfoot' => 'MUtil_Html_TBodyElement::tfoot', - 'thead' => 'MUtil_Html_TBodyElement::thead', - 'tr' => 'MUtil_Html_TrElement::tr', - 'ul' => 'MUtil_Html_ListElement::ul', - ); - - public function __call($name, array $arguments) - { - return $this->create($name, $arguments); - } - - public function __construct($elementFunctions = null, $attributeFunctions = null, $append = true) - { - $this->setElementFunctionList($elementFunctions, $append); - $this->setAttributeFunctionList($attributeFunctions, $append); - } - - public function addAttributeFunction($name_1, $function_1, $name_n = null, $function_n = null) - { - $args = MUtil_Ra::pairs(func_get_args()); - - return $this->setAttributeFunctionList($args, true); - } - - public function addElementFunction($name_1, $function_1, $name_n = null, $function_n = null) - { - $args = MUtil_Ra::pairs(func_get_args()); - - $this->setElementFunctionList($args, true); - - return $this; - } - - public function create($tagName, array $args = array()) - { - if ($function = $this->_elementFunctionList->get($tagName)) { - return call_user_func_array($function, $args); - - } else { - return new MUtil_Html_HtmlElement($tagName, $args); - } - } - - public function createAttribute($attributeName, array $args = array()) - { - if ($function = $this->_attributeFunctionList->get($attributeName)) { - return call_user_func($function, $args); - - } else { - return new MUtil_Html_ArrayAttribute($attributeName, $args); - - } - } - - public function createRaw($tagName, array $args = array()) - { - return new MUtil_Html_HtmlElement($tagName, $args); - } - - public function getAttributeFunctionList() - { - return $this->_attributeFunctionList; - } - - public function getElementFunctionList() - { - return $this->_elementFunctionList; - } - - public function setAttributeFunctionList($attributeFunctions, $append = false) - { - if ($attributeFunctions instanceof MUtil_Util_LookupList) { - $this->_attributeFunctionList = $attributeFunctions; - } else { - $this->_attributeFunctionList = new MUtil_Util_FunctionList($this->_initialAttributeFunctions); - - if ($attributeFunctions) { - if ($append) { - $this->_attributeFunctionList->add((array) $attributeFunctions); - } else { - $this->_attributeFunctionList->set((array) $attributeFunctions); - } - } - } - return $this; - } - - public function setElementFunctionList($elementFunctions, $append = false) - { - if ($elementFunctions instanceof MUtil_Util_LookupList) { - $this->_elementFunctionList = $elementFunctions; - } else { - if (! $this->_elementFunctionList instanceof MUtil_Util_FunctionList) { - $this->_elementFunctionList = new MUtil_Util_FunctionList($this->_initalElementFunctions); - } - - if ($elementFunctions) { - if ($append) { - $this->_elementFunctionList->add((array) $elementFunctions); - } else { - $this->_elementFunctionList->set((array) $elementFunctions); - } - } - } - return $this; - } -} Copied: tags/MUtil_1.2/Html/Creator.php (from rev 1074, trunk/library/classes/MUtil/Html/Creator.php) =================================================================== --- tags/MUtil_1.2/Html/Creator.php (rev 0) +++ tags/MUtil_1.2/Html/Creator.php 2012-12-29 19:32:02 UTC (rev 1078) @@ -0,0 +1,237 @@ +<?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. + * + * @package MUtil + * @subpackage Html + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $id: Creator.php 362 2011-12-15 17:21:17Z matijsdejong $ + */ + +/** + * Class for storing references for creating html attributes, elements and other objects. + * + * Basically this class stores list of element and attributes names that should be treated + * in different from just creating the most basic of element types. + * + * @package MUtil + * @subpackage Html + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 + */ + +class MUtil_Html_Creator +{ + /** + * + * @var MUtil_Util_LookupList + */ + protected $_attributeFunctionList; + + /** + * + * @var MUtil_Util_LookupList + */ + protected $_elementFunctionList; + + /** + * + * @var array + */ + protected $_initialAttributeFunctions = array( + 'href' => 'MUtil_Html_HrefArrayAttribute::hrefAttribute', + 'onclick' => 'MUtil_Html_OnClickArrayAttribute::onclickAttribute', + 'src' => 'MUtil_Html_SrcArrayAttribute::srcAttribute', + 'style' => 'MUtil_Html_StyleArrayAttribute::styleAttribute', + ); + + /** + * + * @var array + */ + protected $_initalElementFunctions = array( + 'a' => 'MUtil_Html_AElement::a', + 'array' => 'MUtil_Html_Sequence::createSequence', + 'call' => 'MUtil_Lazy::call', + 'col' => 'MUtil_Html_ColElement::col', + 'colgroup' => 'MUtil_Html_ColGroupElement::colgroup', + 'dir' => 'MUtil_Html_ListElement::dir', + 'dd' => 'MUtil_Html_DdElement::dd', + 'dl' => 'MUtil_Html_DlElement::dl', + 'dt' => 'MUtil_Html_DtElement::dt', + 'echo' => 'MUtil_Html_TableElement::createVar', + 'email' => 'MUtil_Html_AElement::email', + 'h1' => 'MUtil_Html_HnElement::h1', + 'h2' => 'MUtil_Html_HnElement::h2', + 'h3' => 'MUtil_Html_HnElement::h3', + 'h4' => 'MUtil_Html_HnElement::h4', + 'h5' => 'MUtil_Html_HnElement::h5', + 'h6' => 'MUtil_Html_HnElement::h6', + 'if' => 'MUtil_Lazy::iff', + 'iflink' => 'MUtil_Html_AElement::iflink', + 'ifmail' => 'MUtil_Html_AElement::ifmail', + 'iframe' => 'MUtil_Html_IFrameElement::iFrame', + 'img' => 'MUtil_Html_ImgElement::img', + 'image' => 'MUtil_Html_ImgElement::img', + 'input' => 'MUtil_Html_InputRenderer::input', + 'inputComplete' => 'MUtil_Html_InputRenderer::inputComplete', + 'inputDescription' => 'MUtil_Html_InputRenderer::inputDescription', + 'inputDisplayGroup' => 'MUtil_Html_InputRenderer::inputDisplayGroup', + 'inputElement' => 'MUtil_Html_InputRenderer::inputElement', + 'inputErrors' => 'MUtil_Html_InputRenderer::inputErrors', + 'inputExcept' => 'MUtil_Html_InputRenderer::inputExcept', + 'inputForm' => 'MUtil_Html_InputRenderer::inputForm', + 'inputLabel' => 'MUtil_Html_LabelElement::label', + 'inputOnly' => 'MUtil_Html_InputRenderer::inputOnly', + 'inputOnlyArray' => 'MUtil_Html_InputRenderer::inputOnlyArray', + 'inputUntil' => 'MUtil_Html_InputRenderer::inputUntil', + 'inputUpto' => 'MUtil_Html_InputRenderer::inputUpto', + 'label' => 'MUtil_Html_LabelElement::label', + 'menu' => 'MUtil_Html_ListElement::menu', + 'ol' => 'MUtil_Html_ListElement::ol', + 'pagePanel' => 'MUtil_Html_PagePanel::pagePanel', + 'pForm' => 'MUtil_Html_PFormElement::pForm', + 'progress' => 'MUtil_Html_ProgressPanel::progress', + 'progressPanel' => 'MUtil_Html_ProgressPanel::progress', + 'raw' => 'MUtil_Html_Raw::raw', + 'seq' => 'MUtil_Html_Sequence::createSequence', + 'sequence' => 'MUtil_Html_Sequence::createSequence', // A sequence can contain another sequence, so other function name used + 'snippet' => 'MUtil_Html::snippet', + 'sprintf' => 'sprintf', + 'spaced' => 'MUtil_Html_Sequence::createSpaced', // A sequence can contain another sequence, so other function name used + 'table' => 'MUtil_Html_TableElement::table', + 'tbody' => 'MUtil_Html_TBodyElement::tbody', + 'tfoot' => 'MUtil_Html_TBodyElement::tfoot', + 'thead' => 'MUtil_Html_TBodyElement::thead', + 'tr' => 'MUtil_Html_TrElement::tr', + 'ul' => 'MUtil_Html_ListElement::ul', + ); + + public function __call($name, array $arguments) + { + return $this->create($name, $arguments); + } + + public function __construct($elementFunctions = null, $attributeFunctions = null, $append = true) + { + $this->setElementFunctionList($elementFunctions, $append); + $this->setAttributeFunctionList($attributeFunctions, $append); + } + + public function addAttributeFunction($name_1, $function_1, $name_n = null, $function_n = null) + { + $args = MUtil_Ra::pairs(func_get_args()); + + return $this->setAttributeFunctionList($args, true); + } + + public function addElementFunction($name_1, $function_1, $name_n = null, $function_n = null) + { + $args = MUtil_Ra::pairs(func_get_args()); + + $this->setElementFunctionList($args, true); + + return $this; + } + + public function create($tagName, array $args = array()) + { + if ($function = $this->_elementFunctionList->get($tagName)) { + return call_user_func_array($function, $args); + + } else { + return new MUtil_Html_HtmlElement($tagName, $args); + } + } + + public function createAttribute($attributeName, array $args = array()) + { + if ($function = $this->_attributeFunctionList->get($attributeName)) { + return call_user_func($function, $args); + + } else { + return new MUtil_Html_ArrayAttribute($attributeName, $args); + + } + } + + public function createRaw($tagName, array $args = array()) + { + return new MUtil_Html_HtmlElement($tagName, $args); + } + + public function getAttributeFunctionList() + { + return $this->_attributeFunctionList; + } + + public function getElementFunctionList() + { + return $this->_elementFunctionList; + } + + public function setAttributeFunctionList($attributeFunctions, $append = false) + { + if ($attributeFunctions instanceof MUtil_Util_LookupList) { + $this->_attributeFunctionList = $attributeFunctions; + } else { + $this->_attributeFunctionList = new MUtil_Util_FunctionList($this->_initialAttributeFunctions); + + if ($attributeFunctions) { + if ($append) { + $this->_attributeFunctionList->add((array) $attributeFunctions); + } else { + $this->_attributeFunctionList->set((array) $attributeFunctions); + } + } + } + return $this; + } + + public function setElementFunctionList($elementFunctions, $append = false) + { + if ($elementFunctions instanceof MUtil_Util_LookupList) { + $this->_elementFunctionList = $elementFunctions; + } else { + if (! $this->_elementFunctionList instanceof MUtil_Util_FunctionList) { + $this->_elementFunctionList = new MUtil_Util_FunctionList($this->_initalElementFunctions); + } + + if ($elementFunctions) { + if ($append) { + $this->_elementFunctionList->add((array) $elementFunctions); + } else { + $this->_elementFunctionList->set((array) $elementFunctions); + } + } + } + return $this; + } +} Deleted: tags/MUtil_1.2/Html/Renderer.php =================================================================== --- trunk/library/classes/MUtil/Html/Renderer.php 2012-12-27 14:35:57 UTC (rev 1073) +++ tags/MUtil_1.2/Html/Renderer.php 2012-12-29 19:32:02 UTC (rev 1078) @@ -1,239 +0,0 @@ -<?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. - * - * @package MUtil - * @subpackage Html - * @author Matijs de Jong <mj...@ma...> - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @version $id: Renderer.php 362 2011-12-15 17:21:17Z matijsdejong $ - */ - -/** - * Render output for a view. - * - * This object handles MUtil_Html_HtmlInterface and MUtil_Lazy_LazyInterface - * objects natively, as well as array, scalar values and objects with a - * __toString function. - * - * All other object types passed to the renderer should have a render function - * defined for them in the ClassRenderList. - * - * @package MUtil - * @subpackage Html - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @since Class available since version 1.0 - */ -class MUtil_Html_Renderer -{ - /** - * - * @var MUtil_Util_ClassList - */ - protected $_classRenderFunctions; - - /** - * Default array of objects rendering functions. - * - * The MUtil_Html_Renderer::doNotRender function allows items to be passed - * as content without triggering error messages. - * - * This is usefull if you want to pass an item to sub objects, but are not - * sure that it will be used in every case. - * - * @var array classname => static output function - */ - protected $_initialClassRenderFunctions = array( - 'Zend_Db_Adapter_Abstract' => 'MUtil_Html_Renderer::doNotRender', - 'Zend_Controller_Request_Abstract' => 'MUtil_Html_Renderer::doNotRender', - 'Zend_Form' => 'MUtil_Html_InputRenderer::renderForm', - 'Zend_Form_DisplayGroup' => 'MUtil_Html_InputRenderer::renderDisplayGroup', - 'Zend_Form_Element' => 'MUtil_Html_InputRenderer::renderElement', - 'Zend_Translate' => 'MUtil_Html_Renderer::doNotRender', - ); - - /** - * Create the renderer - * - * @param mixed $classRenderFunctions Array of classname => renderFunction or MUtil_Util_ClassList - * @param boolean $append Replace when false, append to default definitions otherwise - */ - public function __construct($classRenderFunctions = null, $append = true) - { - $this->setClassRenderList($classRenderFunctions, $append); - } - - /** - * Check if the value can be rendered by this object - * - * @param mixed $value - * @return boolean True when the object can be rendered - */ - public function canRender($value) - { - if (is_object($value)) { - if (method_exists($value, '__toString') || - ($value instanceof MUtil_Lazy_LazyInterface) || - ($value instanceof MUtil_Html_HtmlInterface)) { - return true; - } - - return $this->_classRenderFunctions->get($content); - - } else { - if (is_array($value)) { - foreach ($value as $key => $val) { - if (! $this->canRender($val)) { - return false; - } - } - } - - return true; - } - } - - /** - * Static helper function used for object types that should - * not produce output when (accidently) rendered. - * - * Eg Zend_Translate or Zend_Db_Adapter_Abstract - * - * @param Zend_View_Abstract $view - * @param mixed $content - * @return null - */ - public static function doNotRender(Zend_View_Abstract $view, $content) - { - if (MUtil_Html::$verbose) { - MUtil_Echo::r('Did not render ' . get_class($content) . ' object.'); - } - return null; - } - - /** - * Get the classlist containing render functions for non-builtin objects - * - * @return MUtil_Util_ClassList - */ - public function getClassRenderList() - { - return $this->_classRenderFunctions; - } - - /** - * Renders the $content so that it can be used as output for the $view, - * including output escaping and encoding correction. - * - * This functions handles MUtil_Html_HtmlInterface and MUtil_Lazy_LazyInterface - * objects natively, as well as array, scalar values and objects with a - * __toString function. - * - * Other objects a definition should have a render function in getClassRenderList(). - * - * All Lazy variabables are raised. - * - * @param Zend_View_Abstract $view - * @param mixed $content Anything HtmlInterface, number, string, array, object with __toString - * or an object that has a defined render function in getClassRenderList(). - * @return string Output to echo to the user - */ - public function renderAny(Zend_View_Abstract $view, $content) - { - // Resolve first as this function as recursion heavy enough as it is. - if ($content instanceof MUtil_Lazy_LazyInterface) { - $content = MUtil_Lazy::rise($content); - } - - if ($content) { - if ($content instanceof MUtil_Html_HtmlInterface) { - $new_content = $content->render($view); - - } elseif (is_array($content) && (! is_object($content))) { - - // Again, skip on the recursion count - foreach ($content as $key => $item) { - $new_content[] = $this->renderAny($view, $item); - } - - return implode('', $new_content); - - } else { - if (is_object($content)) { - if ($function = $this->_classRenderFunctions->get($content)) { - return call_user_func($function, $view, $content); - } - - if (method_exists($content, '__toString')) { - $new_content = $content->__toString(); - } else { - // $new_content = 'WARNING: Object of type ' . get_class($content) . ' cannot be converted to string.'; - throw new MUtil_Html_HtmlException('WARNING: Object of type ' . get_class($content) . ' cannot be converted to string.'); - } - } else { - $new_content = (string) $content; - } - - $new_content = $view->escape($new_content); - } - - return $new_content; - - } - - if (! is_array($content)) { // Skip empty array - return $content; // Returns 0 (zero) and '' when that is the value of $content - } - } - - /** - * Change the list of non-builtin objects that can be rendered by this renderer. - * - * @param mixed $classRenderFunctions Array of classname => renderFunction or MUtil_Util_ClassList - * @param boolean $append Replace when false, append otherwise - * @return MUtil_Html_Renderer (continuation pattern) - */ - public function setClassRenderList($classRenderFunctions = null, $append = false) - { - if ($classRenderFunctions instanceof MUtil_Util_ClassList) { - $this->_classRenderFunctions = $classRenderFunctions; - } else { - $this->_classRenderFunctions = new MUtil_Util_ClassList($this->_initialClassRenderFunctions); - - if ($classRenderFunctions) { - if ($append) { - $this->_classRenderFunctions->add((array) $classRenderFunctions); - } else { - $this->_classRenderFunctions->set((array) $classRenderFunctions); - } - } - } - return $this; - } -} Copied: tags/MUtil_1.2/Html/Renderer.php (from rev 1076, trunk/library/classes/MUtil/Html/Renderer.php) =================================================================== --- tags/MUtil_1.2/Html/Renderer.php (rev 0) +++ tags/MUtil_1.2/Html/Renderer.php 2012-12-29 19:32:02 UTC (rev 1078) @@ -0,0 +1,239 @@ +<?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. + * + * @package MUtil + * @subpackage Html + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $id: Renderer.php 362 2011-12-15 17:21:17Z matijsdejong $ + */ + +/** + * Render output for a view. + * + * This object handles MUtil_Html_HtmlInterface and MUtil_Lazy_LazyInterface + * objects natively, as well as array, scalar values and objects with a + * __toString function. + * + * All other object types passed to the renderer should have a render function + * defined for them in the ClassRenderList. + * + * @package MUtil + * @subpackage Html + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 + */ +class MUtil_Html_Renderer +{ + /** + * + * @var MUtil_Util_ClassList + */ + protected $_classRenderFunctions; + + /** + * Default array of objects rendering functions. + * + * The MUtil_Html_Renderer::doNotRender function allows items to be passed + * as content without triggering error messages. + * + * This is usefull if you want to pass an item to sub objects, but are not + * sure that it will be used in every case. + * + * @var array classname => static output function + */ + protected $_initialClassRenderFunctions = array( + 'Zend_Db_Adapter_Abstract' => 'MUtil_Html_Renderer::doNotRender', + 'Zend_Controller_Request_Abstract' => 'MUtil_Html_Renderer::doNotRender', + 'Zend_Form' => 'MUtil_Html_InputRenderer::renderForm', + 'Zend_Form_DisplayGroup' => 'MUtil_Html_InputRenderer::renderDisplayGroup', + 'Zend_Form_Element' => 'MUtil_Html_InputRenderer::renderElement', + 'Zend_Translate' => 'MUtil_Html_Renderer::doNotRender', + ); + + /** + * Create the renderer + * + * @param mixed $classRenderFunctions Array of classname => renderFunction or MUtil_Util_ClassList + * @param boolean $append Replace when false, append to default definitions otherwise + */ + public function __construct($classRenderFunctions = null, $append = true) + { + $this->setClassRenderList($classRenderFunctions, $append); + } + + /** + * Check if the value can be rendered by this object + * + * @param mixed $value + * @return boolean True when the object can be rendered + */ + public function canRender($value) + { + if (is_object($value)) { + if (($value instanceof MUtil_Lazy_LazyInterface) || + ($value instanceof MUtil_Html_HtmlInterface) || + method_exists($value, '__toString')) { + return true; + } + + return $this->_classRenderFunctions->get($value); + + } else { + if (is_array($value)) { + foreach ($value as $key => $val) { + if (! $this->canRender($val)) { + return false; + } + } + } + + return true; + } + } + + /** + * Static helper function used for object types that should + * not produce output when (accidently) rendered. + * + * Eg Zend_Translate or Zend_Db_Adapter_Abstract + * + * @param Zend_View_Abstract $view + * @param mixed $content + * @return null + */ + public static function doNotRender(Zend_View_Abstract $view, $content) + { + if (MUtil_Html::$verbose) { + MUtil_Echo::r('Did not render ' . get_class($content) . ' object.'); + } + return null; + } + + /** + * Get the classlist containing render functions for non-builtin objects + * + * @return MUtil_Util_ClassList + */ + public function getClassRenderList() + { + return $this->_classRenderFunctions; + } + + /** + * Renders the $content so that it can be used as output for the $view, + * including output escaping and encoding correction. + * + * This functions handles MUtil_Html_HtmlInterface and MUtil_Lazy_LazyInterface + * objects natively, as well as array, scalar values and objects with a + * __toString function. + * + * Other objects a definition should have a render function in getClassRenderList(). + * + * All Lazy variabables are raised. + * + * @param Zend_View_Abstract $view + * @param mixed $content Anything HtmlInterface, number, string, array, object with __toString + * or an object that has a defined render function in getClassRenderList(). + * @return string Output to echo to the user + */ + public function renderAny(Zend_View_Abstract $view, $content) + { + // Resolve first as this function as recursion heavy enough as it is. + if ($content instanceof MUtil_Lazy_LazyInterface) { + $content = MUtil_Lazy::rise($content); + } + + if ($content) { + if ($content instanceof MUtil_Html_HtmlInterface) { + $new_content = $content->render($view); + + } elseif (is_array($content) && (! is_object($content))) { + + // Again, skip on the recursion count + foreach ($content as $key => $item) { + $new_content[] = $this->renderAny($view, $item); + } + + return implode('', $new_content); + + } else { + if (is_object($content)) { + if ($function = $this->_classRenderFunctions->get($content)) { + return call_user_func($function, $view, $content); + } + + if (method_exists($content, '__toString')) { + $new_content = $content->__toString(); + } else { + // $new_content = 'WARNING: Object of type ' . get_class($content) . ' cannot be converted to string.'; + throw new MUtil_Html_HtmlException('WARNING: Object of type ' . get_class($content) . ' cannot be converted to string.'); + } + } else { + $new_content = (string) $content; + } + + $new_content = $view->escape($new_content); + } + + return $new_content; + + } + + if (! is_array($content)) { // Skip empty array + return $content; // Returns 0 (zero) and '' when that is the value of $content + } + } + + /** + * Change the list of non-builtin objects that can be rendered by this renderer. + * + * @param mixed $classRenderFunctions Array of classname => renderFunction or MUtil_Util_ClassList + * @param boolean $append Replace when false, append otherwise + * @return MUtil_Html_Renderer (continuation pattern) + */ + public function setClassRenderList($classRenderFunctions = null, $append = false) + { + if ($classRenderFunctions instanceof MUtil_Util_ClassList) { + $this->_classRenderFunctions = $classRenderFunctions; + } else { + $this->_classRenderFunctions = new MUtil_Util_ClassList($this->_initialClassRenderFunctions); + + if ($classRenderFunctions) { + if ($append) { + $this->_classRenderFunctions->add((array) $classRenderFunctions); + } else { + $this->_classRenderFunctions->set((array) $classRenderFunctions); + } + } + } + return $this; + } +} Deleted: tags/MUtil_1.2/Model/TableModel.php =================================================================== --- trunk/library/classes/MUtil/Model/TableModel.php 2012-12-27 14:35:57 UTC (rev 1073) +++ tags/MUtil_1.2/Model/TableModel.php 2012-12-29 19:32:02 UTC (rev 1078) @@ -1,128 +0,0 @@ -<?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. - * - * - * @package MUtil - * @subpackage Model - * @author Matijs de Jong <mj...@ma...> - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @version $Id$ - */ - -/** - * A simple mode for a single table - * - * @package MUtil - * @subpackage Model - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @since Class available since version 1.2 - */ -class MUtil_Model_TableModel extends MUtil_Model_DatabaseModelAbstract -{ - /** - * - * @var Zend_Db_Table_Abstract - */ - private $_table; - - public function __construct($table, $altName = null) - { - if ($table instanceof Zend_Db_Table_Abstract) { - $this->_table = $table; - $table_name = $this->_getTableName($table); - } else { - $this->_table = new Zend_DB_Table($table); - $table_name = $table; - } - - parent::__construct(null === $altName ? $table_name : $altName); - - $this->_loadTableMetaData($this->_table); - } - - /** - * Delete items from the model - * - * @param mixed $filter True to use the stored filter, array to specify a different filter - * @return int The number of items deleted - */ - public function delete($filter = true) - { - return $this->_deleteTableData( - $this->_table, - $this->_checkFilterUsed($filter), - $this->_deleteValues); - } - - /** - * The database adapter used by the model. - * - * @return Zend_Db_Adapter_Abstract - */ - public function getAdapter() - { - return $this->_table->getAdapter(); - } - - /** - * Returns a Zend_Db_Table_Select object to work with - * - * @return Zend_Db_Table_Select - */ - public function getSelect() - { - if ($this->hasItemsUsed()) { - $select = $this->_table->select(Zend_Db_Table_Abstract::SELECT_WITHOUT_FROM_PART); - $select->from($this->_getTableName($this->_table), array()); - return $select; - } else { - return $this->_table->select(Zend_Db_Table_Abstract::SELECT_WITH_FROM_PART); - } - } - - /** - * Save a single model item. - * - * @param array $newValues The values to store for a single model item. - * @param array $filter If the filter contains old key values these are used - * to decide on update versus insert. - * @return array The values as they are after saving (they may change). - */ - public function save(array $newValues, array $filter = null) - { - // $this->_saveTableData returns the new row values, including any automatic changes. - // add $newValues to throw nothing away. - $updatedValues = $this->_saveTableData($this->_table, $newValues, $filter, parent::SAVE_MODE_ALL) + $newValues; - - // Handle possible onLoad - $updatedValues = $this->processAfterLoad(array($updatedValues)); - return reset($updatedValues); - } -} Copied: tags/MUtil_1.2/Model/TableModel.php (from rev 1076, trunk/library/classes/MUtil/Model/TableModel.php) =================================================================== --- tags/MUtil_1.2/Model/TableModel.php (rev 0) +++ tags/MUtil_1.2/Model/TableModel.php 2012-12-29 19:32:02 UTC (rev 1078) @@ -0,0 +1,133 @@ +<?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. + * + * + * @package MUtil + * @subpackage Model + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ + */ + +/** + * A simple mode for a single table + * + * @package MUtil + * @subpackage Model + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.2 + */ +class MUtil_Model_TableModel extends MUtil_Model_DatabaseModelAbstract +{ + /** + * + * @var Zend_Db_Table_Abstract + */ + 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) { + $this->_table = $table; + $table_name = $this->_getTableName($table); + } else { + $this->_table = new Zend_DB_Table($table); + $table_name = $table; + } + + parent::__construct(null === $altName ? $table_name : $altName); + + $this->_loadTableMetaData($this->_table); + } + + /** + * Delete items from the model + * + * @param mixed $filter True to use the stored filter, array to specify a different filter + * @return int The number of items deleted + */ + public function delete($filter = true) + { + return $this->_deleteTableData( + $this->_table, + $this->_checkFilterUsed($filter), + $this->_deleteValues); + } + + /** + * The database adapter used by the model. + * + * @return Zend_Db_Adapter_Abstract + */ + public function getAdapter() + { + return $this->_table->getAdapter(); + } + + /** + * Returns a Zend_Db_Table_Select object to work with + * + * @return Zend_Db_Table_Select + */ + public function getSelect() + { + if ($this->hasItemsUsed()) { + $select = $this->_table->select(Zend_Db_Table_Abstract::SELECT_WITHOUT_FROM_PART); + $select->from($this->_getTableName($this->_table), array()); + return $select; + } else { + return $this->_table->select(Zend_Db_Table_Abstract::SELECT_WITH_FROM_PART); + } + } + + /** + * Save a single model item. + * + * @param array $newValues The values to store for a single model item. + * @param array $filter If the filter contains old key values these are used + * to decide on update versus insert. + * @return array The values as they are after saving (they may change). + */ + public function save(array $newValues, array $filter = null) + { + // $this->_saveTableData returns the new row values, including any automatic changes. + // add $newValues to throw nothing away. + $updatedValues = $this->_saveTableData($this->_table, $newValues, $filter, parent::SAVE_MODE_ALL) + $newValues; + + // Handle possible onLoad + $updatedValues = $this->processAfterLoad(array($updatedValues)); + return reset($updatedValues); + } +} Deleted: tags/MUtil_1.2/Util/ClassList.php =================================================================== --- trunk/library/classes/MUtil/Util/ClassList.php 2012-12-27 14:35:57 UTC (rev 1073) +++ tags/MUtil_1.2/Util/ClassList.php 2012-12-29 19:32:02 UTC (rev 1078) @@ -1,130 +0,0 @@ -<?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 - * @subpackage Util - */ - -/** - * - * @author Matijs de Jong - * @package MUtil - * @subpackage Util - */ -class MUtil_Util_ClassList extends MUtil_Util_LookupList -{ - protected $_subClasses; - protected $_notSubClasses; - - /** - * Function triggered when the underlying lookup array has changed. - * - * This function exists to allow overloading in subclasses. - * - * @return void - */ - protected function _changed() - { - // Clean up caches - $this->_subClasses = array(); - $this->_notSubClasses = array(); - } - - /** - * Item lookup function. - * - * This is a separate function to allow overloading by subclasses. - * - * @param scalar $key - * @param mixed $default - * @return mixed - */ - protected function _getItem($key, $default = null) - { - if (is_object($key)) { - $class = get_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 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; - } - } - - // 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; - - return $default; - } else { - return parent::_getItem($key, $default); - } - } -} \ No newline at end of file Copied: tags/MUtil_1.2/Util/ClassList.php (from rev 1076, trunk/library/classes/MUtil/Util/ClassList.php) =================================================================== --- tags/MUtil_1.2/Util/ClassList.php (rev 0) +++ tags/MUtil_1.2/Util/ClassList.php 2012-12-29 19:32:02 UTC (rev 1078) @@ -0,0 +1,149 @@ +<?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. + * + * + * @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 $ + */ + +/** + * 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; + + /** + * Function triggered when the underlying lookup array has changed. + * + * This function exists to allow overloading in subclasses. + * + * @return void + */ + protected function _changed() + { + // Clean up caches + $this->_subClasses = array(); + $this->_notSubClasses = array(); + } + + /** + * Item lookup function. + * + * This is a separate function to allow overloading by subclasses. + * + * @param scalar $key + * @param mixed $default + * @return mixed + */ + protected function _getItem($key, $default = null) + { + if (is_object($key)) { + $class = get_class($key); + } else { + $class = $key; + } + + // Check for simple 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_k... [truncated message content] |