/**
  * Registers an array of task objects.
  *
  * If you pass null, this method will register all available tasks.
  *
  * @param array $tasks An array of tasks
  */
 public function registerTasks($tasks = null)
 {
     if (is_null($tasks)) {
         $tasks = array();
         foreach (get_declared_classes() as $class) {
             $r = new Reflectionclass($class);
             if ($r->isSubclassOf('sfTask') && !$r->isAbstract()) {
                 $tasks[] = new $class($this->dispatcher, $this->formatter);
             }
         }
     }
     foreach ($tasks as $task) {
         $this->registerTask($task);
     }
 }
예제 #2
0
 /**
  * Reloads tasks.
  *
  * Useful when you install plugins with tasks and if you want to use them with the runTask() method.
  */
 protected function reloadTasks()
 {
     if (null === $this->commandApplication) {
         return;
     }
     $this->configuration = $this->createConfiguration(null, null);
     $this->commandApplication->clearTasks();
     $this->commandApplication->loadTasks($this->configuration);
     $disabledPluginsRegex = sprintf('#^(%s)#', implode('|', array_diff($this->configuration->getAllPluginPaths(), $this->configuration->getPluginPaths())));
     $tasks = array();
     foreach (get_declared_classes() as $class) {
         $r = new Reflectionclass($class);
         if ($r->isSubclassOf('sfTask') && !$r->isAbstract() && !preg_match($disabledPluginsRegex, $r->getFileName())) {
             $tasks[] = new $class($this->dispatcher, $this->formatter);
         }
     }
     $this->commandApplication->registerTasks($tasks);
 }