예제 #1
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.");
     }
 }
예제 #2
0
 /**
  * Store a variable in the general store.
  *
  * These variables have to be reset for every run of the batch.
  *
  * @param string $name Name of the variable
  * @param mixed $variable Something that can be serialized
  * @return \MUtil_Batch_BatchAbstract (continuation pattern)
  */
 public function setVariable($name, $variable)
 {
     parent::setVariable($name, $variable);
     $this->source->addRegistryContainer($this->variables, 'variables');
     return $this;
 }