]> git.mxchange.org Git - mailer.git/blob - inc/classes/main/extended/class_ObjectLimits.php
Launcher scripts updated
[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  * @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  *
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.
16  *
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.
21  *
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/>.
24  */
25 class ObjectLimits extends BaseFrameworkSystem {
26         /**
27          * Limitation array for storing all attribute names we will use later
28          * only.
29          */
30         private $limitArray = null;
31
32         /**
33          * Protected constructor
34          *
35          * @return      void
36          */
37         protected function __construct () {
38                 // Call parent constructor
39                 parent::__construct(__CLASS__);
40
41                 // Clean up a little
42                 $this->removeNumberFormaters();
43         }
44
45         /**
46          * Create a new ObjectLimits object and (maybe prepare it a little)
47          *
48          * @param               $limitationArray        The limitation array we "walk" through
49          * @return      $limitInstance          The instance to an ObjectLimits object
50          */
51         public final static function createObjectLimits (array $limitationArray) {
52                 // Is there a limitation array given?
53                 if (count($limitationArray) > 0) {
54                         // Get instance
55                         $limitInstance = new ObjectLimits();
56
57                         // Get all limitations and do them
58                         foreach ($limitationArray as $limit) {
59                                 // What shall we limitate?
60                                 if ($limit instanceof FrameworkInterface) {
61                                         // Add an object
62                                         $limitInstance->addObject($limit);
63                                 } elseif (is_string($limit)) {
64                                         // Add a string
65                                         $limitInstance->addString($limit);
66                                 } else {
67                                         // Others are not supported (yet)
68                                         throw new UnsupportedLimitationPartException($limit, self::EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED);
69                                 }
70                         }
71
72                         // Return instance
73                         return $limitInstance;
74                 } else {
75                         // No limitation given so we send "null" back
76                         return null;
77                 }
78         }
79
80         /**
81          * Add an object's name to the limitation list
82          *
83          * @param               $object The object's name we shall add to the list
84          * @return      void
85          */
86         private final function addObject (FrameworkInterface $object) {
87                 // Auto-initialization
88                 if (is_null($this->limitArray)) {
89                         // Initialize this array
90                         $this->limitArray = new FrameworkArrayObject("FakedLimitArray");
91                 }
92
93                 // Add the object's name to it
94                 $this->limitArray->append($object->__toString());
95         }
96
97         /**
98          * Add a string directly to the limitation list
99          *
100          * @param               $str            The string we want to add directly
101          * @return      void
102          */
103         private final function addString ($str) {
104                 // Auto-initialization
105                 if (is_null($this->limitArray)) {
106                         // Initialize this array
107                         $this->limitArray = new FrameworkArrayObject("FakedLimitArray");
108                 }
109
110                 // Add the direct string to ArrayObject
111                 $this->limitArray->append($str);
112         }
113
114         /**
115          * Getter for limitArray
116          *
117          * @return      $limitArray     The object ArrayObject which holds limitations
118          */
119         public final function getLimitArray () {
120                 return $this->limitArray;
121         }
122 }
123
124 // [EOF]
125 ?>