/** * Instantiate a new class using the arguments array for initiation * * @param string $className * @param array $arguments Instanciation arguments * @return className */ public function createClass($className, array $arguments = array()) { $object = parent::createClass($className, $arguments); if ($object instanceof \MUtil_Registry_TargetInterface) { if ($this->_source instanceof \MUtil_Registry_SourceInterface) { $this->_source->applySource($object); } elseif (self::$verbose) { \MUtil_Echo::r("Loading target class {$className}, but source not set."); } } return $object; }
/** * 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."); } }
/** * * @param \MUtil_Task_TaskBatch $batch Optional batch with different source etc.. * @return \MUtil_Task_TaskBatch */ public function getImportOnlyBatch(\MUtil_Task_TaskBatch $batch = null) { if (!$this->_importBatch instanceof \MUtil_Task_TaskBatch) { $batch = new \MUtil_Task_TaskBatch(__CLASS__ . '_import_' . basename($this->sourceModel->getName()) . '_' . __FUNCTION__); $this->registrySource->applySource($batch); $batch->setSource($this->registrySource); $batch->setVariable('targetModel', $this->getTargetModel()); $this->_importBatch = $batch; } else { $batch = $this->_importBatch; } $this->_importBatch->getStack()->registerAllowedClass('MUtil_Date'); // \MUtil_Echo::track($this->_importBatch->count()); if (!$batch->isLoaded()) { if ($this->_filename) { $batch->addTask('AddTask', 'File_CopyFileWhenTask', $this->_filename, $this->getSuccessDirectory() . DIRECTORY_SEPARATOR . $this->getLongtermFilename() . '.' . $this->_extension, 'import_errors', 0, 0); } // Rest of loading is done by getCheckOnlyBatch, but when started, the above task must be added. } return $this->_importBatch; }
/** * 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; }