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
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.
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.
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/>.
25 class ObjectLimits extends BaseFrameworkSystem {
27 * Limitation array for storing all attribute names we will use later
30 private $limitArray = null;
33 * Protected constructor
37 protected function __construct () {
38 // Call parent constructor
39 parent::__construct(__CLASS__);
41 // Set part description
42 $this->setObjectDescription("Class for "limiting" other classes. See description for details.");
44 // Create unique ID number
45 $this->createUniqueID();
48 $this->removeNumberFormaters();
52 * Create a new ObjectLimits object and (maybe prepare it a little)
54 * @param $limitationArray The limitation array we "walk" through
55 * @return $limitInstance The instance to an ObjectLimits object
57 public final static function createObjectLimits (array $limitationArray) {
58 // Is there a limitation array given?
59 if (count($limitationArray) > 0) {
61 $limitInstance = new ObjectLimits();
63 // Get all limitations and do them
64 foreach ($limitationArray as $limit) {
65 // What shall we limitate?
66 if ($limit instanceof FrameworkInterface) {
68 $limitInstance->addObject($limit);
69 } elseif (is_string($limit)) {
71 $limitInstance->addString($limit);
73 // Others are not supported (yet)
74 throw new UnsupportedLimitationPartException($limit, self::EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED);
79 return $limitInstance;
81 // No limitation given so we send "null" back
87 * Add an object's name to the limitation list
89 * @param $object The object's name we shall add to the list
92 private final function addObject (FrameworkInterface $object) {
93 // Auto-initialization
94 if (is_null($this->limitArray)) {
95 // Initialize this array
96 $this->limitArray = new FrameworkArrayObject();
99 // Add the object's name to it
100 $this->limitArray->append($object->__toString());
104 * Add a string directly to the limitation list
106 * @param $str The string we want to add directly
109 private final function addString ($str) {
110 // Auto-initialization
111 if (is_null($this->limitArray)) {
112 // Initialize this array
113 $this->limitArray = new FrameworkArrayObject();
116 // Add the direct string to ArrayObject
117 $this->limitArray->append($str);
121 * Getter for limitArray
123 * @return $limitArray The object ArrayObject which holds limitations
125 public final function getLimitArray () {
126 return $this->limitArray;