]> git.mxchange.org Git - hub.git/blobdiff - inc/classes/main/extended/class_ObjectLimits.php
some comments fixed, small fix for windows OSes and some other things fixed
[hub.git] / inc / classes / main / extended / class_ObjectLimits.php
diff --git a/inc/classes/main/extended/class_ObjectLimits.php b/inc/classes/main/extended/class_ObjectLimits.php
new file mode 100644 (file)
index 0000000..91dc519
--- /dev/null
@@ -0,0 +1,131 @@
+<?php
+/**
+ * This object limits other objects. This is mostly being used to prepare
+ * objects to the datatabase connection or else a lot heap would be saved.
+ *
+ * @author             Roland Haeder <webmaster@mxchange.org>
+ * @version            0.3.0
+ * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.mxchange.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+class ObjectLimits extends BaseFrameworkSystem {
+       /**
+        * Limitation array for storing all attribute names we will use later
+        * only.
+        */
+       private $limitArray = null;
+
+       /**
+        * Private constructor
+        *
+        * @return      void
+        */
+       private final function __construct () {
+               // Call parent constructor
+               parent::constructor(__CLASS__);
+
+               // Set part description
+               $this->setPartDescr("Limitierungsobjekt");
+
+               // Create unique ID number
+               $this->createUniqueID();
+
+               // Clean up a little
+               $this->removeNumberFormaters();
+       }
+
+       /**
+        * Create a new ObjectLimits object and (maybe prepare it a little)
+        *
+        * @param               $limitationArray        The limitation array we "walk" through
+        * @return      $limitInstance          The instance to an ObjectLimits object
+        */
+       public final static function createObjectLimits (array $limitationArray) {
+               // Is there a limitation array given?
+               if (count($limitationArray) > 0) {
+                       // Get instance
+                       $limitInstance = new ObjectLimits();
+
+                       // Get all limitations and do them
+                       foreach ($limitationArray as $limit) {
+                               // What shall we limitate?
+                               if ($limit instanceof FrameworkInterface) {
+                                       // Add an object
+                                       $limitInstance->addObject($limit);
+                               } elseif (is_string($limit)) {
+                                       // Add a string
+                                       $limitInstance->addString($limit);
+                               } else {
+                                       // Others are not supported (yet)
+                                       throw new UnsupportedLimitationPartException($limit, self::EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED);
+                               }
+                       }
+
+                       // Return instance
+                       return $limitInstance;
+               } else {
+                       // No limitation given so we send "null" back
+                       return null;
+               }
+       }
+
+       /**
+        * Add an object's name to the limitation list
+        *
+        * @param               $object The object's name we shall add to the list
+        * @return      void
+        */
+       private final function addObject (FrameworkInterface $object) {
+               // Auto-initialization
+               if (is_null($this->limitArray)) {
+                       // Initialize this array
+                       $this->limitArray = new FrameworkArrayObject();
+               }
+
+               // Add the object's name to it
+               $this->limitArray->append($object->__toString());
+       }
+
+       /**
+        * Add a string directly to the limitation list
+        *
+        * @param               $str            The string we want to add directly
+        * @return      void
+        */
+       private final function addString ($str) {
+               // Auto-initialization
+               if (is_null($this->limitArray)) {
+                       // Initialize this array
+                       $this->limitArray = new FrameworkArrayObject();
+               }
+
+               // Add the direct string to ArrayObject
+               $this->limitArray->append($str);
+       }
+
+       /**
+        * Getter for limitArray
+        *
+        * @return      $limitArray     The object ArrayObject which holds limitations
+        */
+       public final function getLimitArray () {
+               return $this->limitArray;
+       }
+}
+
+// [EOF]
+?>