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
10 * @link http://www.ship-simu.org
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.
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.
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/>.
26 class ObjectLimits extends BaseFrameworkSystem {
28 * Limitation array for storing all attribute names we will use later
31 private $limitArray = null;
34 * Protected constructor
38 protected function __construct () {
39 // Call parent constructor
40 parent::__construct(__CLASS__);
42 // Set part description
43 $this->setObjectDescription("Class for "limiting" other classes. See description for details.");
45 // Create unique ID number
46 $this->generateUniqueId();
49 $this->removeNumberFormaters();
53 * Create a new ObjectLimits object and (maybe prepare it a little)
55 * @param $limitationArray The limitation array we "walk" through
56 * @return $limitInstance The instance to an ObjectLimits object
58 public final static function createObjectLimits (array $limitationArray) {
59 // Is there a limitation array given?
60 if (count($limitationArray) > 0) {
62 $limitInstance = new ObjectLimits();
64 // Get all limitations and do them
65 foreach ($limitationArray as $limit) {
66 // What shall we limitate?
67 if ($limit instanceof FrameworkInterface) {
69 $limitInstance->addObject($limit);
70 } elseif (is_string($limit)) {
72 $limitInstance->addString($limit);
74 // Others are not supported (yet)
75 throw new UnsupportedLimitationPartException($limit, self::EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED);
80 return $limitInstance;
82 // No limitation given so we send "null" back
88 * Add an object's name to the limitation list
90 * @param $object The object's name we shall add to the list
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');
100 // Add the object's name to it
101 $this->limitArray->append($object->__toString());
105 * Add a string directly to the limitation list
107 * @param $str The string we want to add directly
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");
117 // Add the direct string to ArrayObject
118 $this->limitArray->append($str);
122 * Getter for limitArray
124 * @return $limitArray The object ArrayObject which holds limitations
126 public final function getLimitArray () {
127 return $this->limitArray;