3 * This class contains object attributes which we can now send together to
6 * @author Roland Haeder <webmaster@mxchange.org>
8 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.mxchange.org
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class SerializationContainer extends FrameworkArrayObject {
27 * Public constructor, if you like to have an object of this class...
31 public function __construct () {
32 // Call parent constructor
33 parent::constructor(__CLASS__);
36 if ((defined('DEBUG_CONTAINER')) && (defined('DEBUG_CONSTRUCT'))) $this->getDebugInstance()->output("[SerializationContainer:] Konstruktor erreicht.<br />\n");
40 * Create a SerializationContainer object by applying the limitations
41 * in $limitInstance on $object. The resulting data container will only
42 * hold the attributed and their values which we have specified in
43 * the limitation object.
45 * @param $limitInstance The instance to the object ObjectLimits
46 * @param $object The origin object. We don't touch it here.
47 * @return $containerInstance An instance of SerializationContainer
48 * @throws GetterNotFoundException If a getter was not found
50 public final static function createSerializationContainer (ObjectLimits $limitInstance, $object) {
52 $containerInstance = new SerializationContainer();
54 // Iterate through the whole limitation array
55 for ($idx = $limitInstance->getLimitArray()->getIterator(); $idx->valid(); $idx->next()) {
56 // Get current item from list
57 $curr = ucfirst($idx->current());
59 // Is the required method available?
60 if (method_exists($object, sprintf("get%s", $curr))) {
61 // Generate a command for getting it
62 $eval = sprintf("\$value = \$object->get%s();",
67 if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $limitInstance->getDebugInstance()->output(sprintf("[%s:] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
75 // Add this item to the container list
76 $containerInstance->append(array(
82 throw new GetterNotFoundException(array($object, $curr), self::EXCEPTION_GETTER_IS_MISSING);
86 // Return container instance
87 return $containerInstance;