0.3.0 inital import
[mailer.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 class SerializationContainer extends FrameworkArrayObject {
7         /**
8          * Public constructor, if you like to have an object of this class...
9          *
10          * @return      void
11          */
12         public function __construct () {
13                 // Call parent constructor
14                 parent::constructor(__CLASS__);
15
16                 // Debug message
17                 if ((defined('DEBUG_CONTAINER')) && (defined('DEBUG_CONSTRUCT'))) $this->getDebugInstance()->output("[SerializationContainer:] Konstruktor erreicht.<br />\n");
18         }
19
20         /**
21          * Create a SerializationContainer object by applying the limitations
22          * in $limitInstance on $object. The resulting data container will only
23          * hold the attributed and their values which we have specified in
24          * the limitation object.
25          *
26          * @param               $limitInstance                  The instance to the object ObjectLimits
27          * @param               $object                         The origin object. We don't touch it here.
28          * @return      $containerInstance              An instance of SerializationContainer
29          * @throws      GetterNotFoundException If a getter was not found
30          */
31         public final static function createSerializationContainer (ObjectLimits $limitInstance, $object) {
32                 // Get an instance
33                 $containerInstance = new SerializationContainer();
34
35                 // Iterate through the whole limitation array
36                 for ($idx = $limitInstance->getLimitArray()->getIterator(); $idx->valid(); $idx->next()) {
37                         // Get current item from list
38                         $curr = ucfirst($idx->current());
39
40                         // Is the required method available?
41                         if (method_exists($object, sprintf("get%s", $curr))) {
42                                 // Generate a command for getting it
43                                 $eval = sprintf("\$value = \$object->get%s();",
44                                         $curr
45                                 );
46
47                                 // Debug eval command
48                                 if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $limitInstance->getDebugInstance()->output(sprintf("[%s:] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
49                                         $this->__toString(),
50                                         htmlentities($eval)
51                                 ));
52
53                                 // Run it
54                                 @eval($eval);
55
56                                 // Add this item to the container list
57                                 $containerInstance->append(array(
58                                         'name'  => $curr,
59                                         'value' => $value
60                                 ));
61                         } else {
62                                 // Throw an exception
63                                 throw new GetterNotFoundException(array($object, $curr), self::EXCEPTION_GETTER_IS_MISSING);
64                         }
65                 } // END - for
66
67                 // Return container instance
68                 return $containerInstance;
69         }
70 }
71
72 // [EOF]
73 ?>