]> git.mxchange.org Git - shipsimu.git/blob - inc/classes/main/extended/class_SerializationContainer.php
98439122c622033ec744b5e8b31b0fbf80d03e5b
[shipsimu.git] / inc / classes / main / extended / class_SerializationContainer.php
1 <?php
2 /**
3  * This class contains object attributes which we can now send together to
4  * other classes
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0.0
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.ship-simu.org
11  * @deprecated
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26 class SerializationContainer extends FrameworkArrayObject {
27         /**
28          * Protected constructor, must stay as public... *sigh*
29          *
30          * @return      void
31          */
32         public function __construct () {
33                 // Call parent constructor
34                 parent::__construct(__CLASS__);
35         }
36
37         /**
38          * Create a SerializationContainer object by applying the limitations
39          * in $limitInstance on $object. The resulting data container will only
40          * hold the attributed and their values which we have specified in
41          * the limitation object.
42          *
43          * @param       $limitInstance          The instance to the object ObjectLimits
44          * @param       $object                         The origin object. We don't touch it here.
45          * @return      $containerInstance      An instance of SerializationContainer
46          * @throws      GetterNotFoundException If a getter was not found
47          */
48         public final static function createSerializationContainer (ObjectLimits $limitInstance, FrameworkInterface $object) {
49                 // Get an instance
50                 $containerInstance = new SerializationContainer();
51
52                 // Iterate through the whole limitation array
53                 for ($idx = $limitInstance->getLimitArray()->getIterator(); $idx->valid(); $idx->next()) {
54                         // Get current item from list
55                         $curr = ucfirst($idx->current());
56
57                         // Is the required method available?
58                         if (method_exists($object, sprintf("get%s", $curr))) {
59                                 // Generate call-back function
60                                 $value = call_user_func_array(array($object, sprintf("get%s", $curr)));
61
62                                 // Add this item to the container list
63                                 $containerInstance->append(array(
64                                         'name'  => $curr,
65                                         'value' => $value
66                                 ));
67                         } else {
68                                 // Throw an exception
69                                 throw new GetterNotFoundException(array($object, $curr), self::EXCEPTION_GETTER_IS_MISSING);
70                         }
71                 } // END - for
72
73                 // Return container instance
74                 return $containerInstance;
75         }
76 }
77
78 // [EOF]
79 ?>