/**
  * Create or loads the class. When only loading, this function returns a StaticCall object that
  * can be invoked lazely.
  *
  * @see \MUtil_Lazy_StaticCall
  * @see \MUtil_Registry_TargetInterface
  *
  * @param string $name The class name, minus the part in $this->_dirs.
  * @param boolean $create Create the object, or only when an \MUtil_Registry_TargetInterface instance.
  * @param array $arguments Class initialization arguments.
  * @return mixed A class instance or a \MUtil_Lazy_StaticCall object
  */
 protected function _loadClass($name, $create = false, array $arguments = array())
 {
     $className = $this->_loader->load($name);
     // \MUtil_Echo::track($className);
     if (is_subclass_of($className, __CLASS__)) {
         $create = true;
         $arguments = array($this->_containers[0], $this->_dirs);
     } elseif (is_subclass_of($className, 'MUtil_Registry_TargetInterface')) {
         $create = true;
     }
     if (!$create) {
         return new \MUtil_Lazy_StaticCall($className);
     }
     $obj = $this->_loader->createClass($className, $arguments);
     if ($obj instanceof \MUtil_Registry_TargetInterface) {
         if (!$this->applySource($obj) && parent::$verbose) {
             \MUtil_Echo::r("Source apply to object of type {$name} failed.", __CLASS__ . '->' . __FUNCTION__);
         }
     }
     return $obj;
 }
예제 #2
0
 /**
  * Searches and loads a .php snippet file.
  *
  * @param string $className The name of the snippet
  * @param array $extraSourceParameters name/value pairs to add to the source for this snippet
  * @return \MUtil_Snippets_SnippetInterface The snippet
  */
 public function getSnippet($className, array $extraSourceParameters = null)
 {
     $className = $this->loader->load($className);
     $snippet = new $className();
     if ($snippet instanceof \MUtil_Snippets_SnippetInterface) {
         // Add extra parameters when specified
         if ($extraSourceParameters) {
             $this->snippetsSource->addRegistryContainer($extraSourceParameters, 'tmpContainer');
         }
         if ($this->snippetsSource->applySource($snippet)) {
             if ($extraSourceParameters) {
                 // Can remove now, it was applied
                 $this->snippetsSource->removeRegistryContainer('tmpContainer');
             }
             return $snippet;
         } else {
             throw new \Zend_Exception("Not all parameters set for html snippet: '{$className}'. \n\nRequested variables were: " . implode(", ", $snippet->getRegistryRequests()));
         }
     } else {
         throw new \Zend_Exception("The snippet: '{$className}' does not implement the \\MUtil_Snippets_SnippetInterface interface.");
     }
 }