Added method to get a certain box by identifier
authorMarcel Werk <burntime@woltlab.com>
Sun, 19 Jun 2016 22:01:07 +0000 (00:01 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 19 Jun 2016 22:01:07 +0000 (00:01 +0200)
wcfsetup/install/files/lib/system/box/BoxHandler.class.php

index 7dae4ea260df61b88519bf3803c6791aa8ff7d86..dba652554d831cc3e840dd3a5b90a8fbef4b64bc 100644 (file)
@@ -24,6 +24,12 @@ class BoxHandler extends SingletonFactory {
         */
        protected $boxes = [];
        
+       /**
+        * identifier to boxes
+        * @var Box[]
+        */
+       protected $boxesByIdentifier = [];
+       
        /**
         * @inheritDoc
         */
@@ -43,6 +49,7 @@ class BoxHandler extends SingletonFactory {
                foreach ($boxList as $box) {
                        if (!isset($this->boxes[$box->position])) $this->boxes[$box->position] = [];
                        $this->boxes[$box->position][] = $box;
+                       $this->boxesByIdentifier[$box->identifier] = $box;
                }
        }
        
@@ -100,4 +107,18 @@ class BoxHandler extends SingletonFactory {
                
                return [];
        }
+       
+       /**
+        * Returns the box with given identifier.
+        *
+        * @param       string          $identifier
+        * @return      Box|null
+        */
+       public function getBoxByIdentifier($identifier) {
+               if (isset($this->boxesByIdentifier[$identifier])) {
+                       return $this->boxesByIdentifier[$identifier];
+               }
+               
+               return null;
+       }
 }