0.3.0 inital import
[mailer.git] / inc / classes / main / extended / class_ObjectLimits.php
1 <?php
2 /**
3  * This object limits other objects. This is mostly being used to prepare
4  * objects to the datatabase connection or else a lot heap would be saved.
5  */
6 class ObjectLimits extends BaseFrameworkSystem {
7         /**
8          * Limitation array for storing all attribute names we will use later
9          * only.
10          */
11         private $limitArray = null;
12
13         /**
14          * Private constructor
15          *
16          * @return      void
17          */
18         private final function __construct () {
19                 // Call parent constructor
20                 parent::constructor(__CLASS__);
21
22                 // Set part description
23                 $this->setPartDescr("Limitierungsobjekt");
24
25                 // Create unique ID number
26                 $this->createUniqueID();
27
28                 // Clean up a little
29                 $this->removeNumberFormaters();
30         }
31
32         /**
33          * Create a new ObjectLimits object and (maybe prepare it a little)
34          *
35          * @param               $limitationArray        The limitation array we "walk" through
36          * @return      $limitInstance          The instance to an ObjectLimits object
37          */
38         public final static function createObjectLimits (array $limitationArray) {
39                 // Is there a limitation array given?
40                 if (count($limitationArray) > 0) {
41                         // Get instance
42                         $limitInstance = new ObjectLimits();
43
44                         // Get all limitations and do them
45                         foreach ($limitationArray as $limit) {
46                                 // What shall we limitate?
47                                 if ($limit instanceof FrameworkInterface) {
48                                         // Add an object
49                                         $limitInstance->addObject($limit);
50                                 } elseif (is_string($limit)) {
51                                         // Add a string
52                                         $limitInstance->addString($limit);
53                                 } else {
54                                         // Others are not supported (yet)
55                                         throw new UnsupportedLimitationPartException($limit, self::EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED);
56                                 }
57                         }
58
59                         // Return instance
60                         return $limitInstance;
61                 } else {
62                         // No limitation given so we send "null" back
63                         return null;
64                 }
65         }
66
67         /**
68          * Add an object's name to the limitation list
69          *
70          * @param               $object The object's name we shall add to the list
71          * @return      void
72          */
73         private final function addObject (FrameworkInterface $object) {
74                 // Auto-initialization
75                 if (is_null($this->limitArray)) {
76                         // Initialize this array
77                         $this->limitArray = new FrameworkArrayObject();
78                 }
79
80                 // Add the object's name to it
81                 $this->limitArray->append($object->__toString());
82         }
83
84         /**
85          * Add a string directly to the limitation list
86          *
87          * @param               $str            The string we want to add directly 
88          * @return      void
89          */
90         private final function addString ($str) {
91                 // Auto-initialization
92                 if (is_null($this->limitArray)) {
93                         // Initialize this array
94                         $this->limitArray = new FrameworkArrayObject();
95                 }
96
97                 // Add the direct string to ArrayObject
98                 $this->limitArray->append($str);
99         }
100
101         /**
102          * Getter for limitArray
103          *
104          * @return      $limitArray     The object ArrayObject which holds limitations
105          */
106         public final function getLimitArray () {
107                 return $this->limitArray;
108         }
109 }
110
111 // [EOF]
112 ?>