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