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