Esempio n. 1
0
 public function setElementFunctionList($elementFunctions, $append = false)
 {
     if ($elementFunctions instanceof \MUtil_Util_LookupList) {
         $this->_elementFunctionList = $elementFunctions;
     } else {
         if (!$this->_elementFunctionList instanceof \MUtil_Util_FunctionList) {
             $this->_elementFunctionList = new \MUtil_Util_FunctionList($this->_initalElementFunctions);
         }
         if ($elementFunctions) {
             if ($append) {
                 $this->_elementFunctionList->add((array) $elementFunctions);
             } else {
                 $this->_elementFunctionList->set((array) $elementFunctions);
             }
         }
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * Item lookup function.
  *
  * This is a separate function to allow overloading by subclasses.
  *
  * @param scalar $key
  * @param mixed $default
  * @return mixed
  */
 protected function _getItem($key, $default = null)
 {
     if (is_object($key)) {
         $class = get_class($key);
     } else {
         $class = $key;
     }
     // Check for simple existence
     if ($result = parent::_getItem($class, $default)) {
         return $result;
     }
     // Check was already found
     if (array_key_exists($class, $this->_subClasses)) {
         return $this->_subClasses[$class];
     }
     // Check was already searched and not found
     if (array_key_exists($class, $this->_notSubClasses)) {
         return $default;
     }
     // Check the parent classes of the object
     $parents = class_parents($key);
     $result = null;
     foreach ($parents as $parentClass) {
         if ($result = parent::_getItem($parentClass, null)) {
             // Add the current class to the cache
             $this->_subClasses[$class] = $result;
             // Add all parents up to the one matching to the cache
             foreach ($parents as $priorParent) {
                 $this->_subClasses[$priorParent] = $result;
                 if ($parentClass === $priorParent) {
                     // Further parents are not automatically in the list
                     break;
                 }
             }
             return $result;
         }
     }
     // Check the interfaces implemented by the object
     $implemented = class_implements($key);
     foreach ($implemented as $interface) {
         if ($result = parent::_getItem($interface, null)) {
             //    Add the current class to the cache
             $this->_subClasses[$class] = $result;
             return $result;
         }
     }
     // Add to the not found cache
     $this->_notSubClasses[$class] = true;
     return $default;
 }