Esempio n. 1
0
 /**
  * DefaultTask constructor.
  * Crawl sources configuration and get data from those readers
  * @param Configuration $config
  */
 public function __construct(Configuration $config)
 {
     // Get sources
     $sources = $config->get(array('sources'), array());
     foreach ($sources as $key => $source) {
         // Skip this source if not defined
         if (!is_array($source) || empty($source)) {
             continue;
         }
         // Empty data array
         $data = array();
         // Create reader with source conf
         $reader = Migrator::createReader(new Configuration($source));
         // Writer will set data in an array
         $writer = new CallbackWriter(function ($item) use(&$data) {
             array_push($data, $item);
         });
         // Create new workflow
         $workflow = new Workflow($reader);
         $workflow->addWriter($writer);
         $workflow->process();
         // Apply data to sources
         $this->sources[$key] = $data;
     }
     if (count($this->sources) > 0) {
         $this->data = current($this->sources);
     }
     // Exec main with this task config
     $this->main($config->export());
 }
Esempio n. 2
0
 /**
  * Create Task from config
  * @return mixed
  * @throws \Exception
  */
 protected function createTask()
 {
     // Split name and prepend Task namespace to it
     $name = $this->conf->get(array('task', 'type'), 'default');
     $namespace = array_merge(array('Task'), explode('/', $name));
     // Summon a Task with the current Migrator config
     return Migrator::summon($namespace, $this->conf->export());
 }