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.
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
9 * @license GNU GPL 3.0 or any newer version
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class ObjectLimits extends BaseFrameworkSystem {
26 * Limitation array for storing all attribute names we will use later
29 private $limitArray = null;
36 private final function __construct () {
37 // Call parent constructor
38 parent::constructor(__CLASS__);
40 // Set part description
41 $this->setPartDescr("Limitierungsobjekt");
43 // Create unique ID number
44 $this->createUniqueID();
47 $this->removeNumberFormaters();
51 * Create a new ObjectLimits object and (maybe prepare it a little)
53 * @param $limitationArray The limitation array we "walk" through
54 * @return $limitInstance The instance to an ObjectLimits object
56 public final static function createObjectLimits (array $limitationArray) {
57 // Is there a limitation array given?
58 if (count($limitationArray) > 0) {
60 $limitInstance = new ObjectLimits();
62 // Get all limitations and do them
63 foreach ($limitationArray as $limit) {
64 // What shall we limitate?
65 if ($limit instanceof FrameworkInterface) {
67 $limitInstance->addObject($limit);
68 } elseif (is_string($limit)) {
70 $limitInstance->addString($limit);
72 // Others are not supported (yet)
73 throw new UnsupportedLimitationPartException($limit, self::EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED);
78 return $limitInstance;
80 // No limitation given so we send "null" back
86 * Add an object's name to the limitation list
88 * @param $object The object's name we shall add to the list
91 private final function addObject (FrameworkInterface $object) {
92 // Auto-initialization
93 if (is_null($this->limitArray)) {
94 // Initialize this array
95 $this->limitArray = new FrameworkArrayObject();
98 // Add the object's name to it
99 $this->limitArray->append($object->__toString());
103 * Add a string directly to the limitation list
105 * @param $str The string we want to add directly
108 private final function addString ($str) {
109 // Auto-initialization
110 if (is_null($this->limitArray)) {
111 // Initialize this array
112 $this->limitArray = new FrameworkArrayObject();
115 // Add the direct string to ArrayObject
116 $this->limitArray->append($str);
120 * Getter for limitArray
122 * @return $limitArray The object ArrayObject which holds limitations
124 public final function getLimitArray () {
125 return $this->limitArray;