Пример #1
0
 /**
  * Describe a task
  *
  * @param Task $task The task
  *
  * @return mixed|string
  */
 public function describeTask(Task $task)
 {
     $description = $task->get('description', null);
     if (!$description) {
         $reflection = new \ReflectionClass($task);
         if ($reflection->getNamespaceName() === 'Netresearch\\Kite') {
             $taskProperty = new \ReflectionProperty('Netresearch\\Kite\\Tasks', 'tasks');
             $taskProperty->setAccessible(true);
             foreach ($taskProperty->getValue($task) as $subTask) {
                 $description .= "\n\n" . $this->describeTask($subTask);
             }
             $description = trim($description);
             if (!$description) {
                 $description = 'Generic ' . $reflection->getName();
             }
         } elseif (preg_match_all('/^ \\* ([^@ \\n].+|)$/mU', $reflection->getDocComment(), $matches, PREG_PATTERN_ORDER)) {
             $description = trim(implode("\n", $matches[1]));
         }
     }
     return $description;
 }
Пример #2
0
 /**
  * Add variables from the task to the job
  *
  * @param Task      $task             The task
  * @param Variables $context          Context to set the variable to, when job is run.
  *                                    When null, variable is set on task
  * @param bool|null $overrideExisting Whether to override existing args (true),
  *                                    don't override them (false) or throw an
  *                                    exception (null)
  *
  * @return void
  */
 public function addVariablesFromTask(Task $task, $context = null, $overrideExisting = null)
 {
     if ($task instanceof Job) {
         foreach ($task->definitions as $from => $definition) {
             if ($context) {
                 $definition['context'] = $context;
             }
             if (!array_key_exists($from, $this->definitions)) {
                 $this->definitions[$from] = $definition;
             }
         }
         return;
     }
     $context = $context ?: $task;
     foreach ($task->get('_variableConfiguration') as $variable => $config) {
         if (!is_array($config)) {
             continue;
         }
         $option = array_key_exists('option', $config) && $config['option'];
         $argument = array_key_exists('argument', $config) && $config['argument'];
         if ($argument && $option) {
             throw new Exception('Variable can not be option and argument at the same time');
         }
         if ($argument || $option) {
             $setting = $argument ?: $option;
             $from = is_string($setting) ? $setting : $this->camelCaseToLowerCaseDashed($variable);
             if (array_key_exists($from, $this->definitions)) {
                 if ($overrideExisting === null) {
                     throw new Exception('Argument/option definitions must be unique');
                 } elseif ($overrideExisting === false) {
                     continue;
                 }
             }
             $this->definitions[$from] = array('context' => $context, 'variable' => $variable, 'type' => $option ? 'option' : 'argument', 'config' => $config);
         }
     }
 }
Пример #3
0
 /**
  * Add a task - or run it immediately when $this->started
  *
  * @param Task $task The task
  *
  * @return $this|mixed $this or the task return value when this is running
  */
 public function addTask(Task $task)
 {
     $deferred = false;
     foreach (array('before', 'after') as $type) {
         if ($task->get($type)) {
             $deferred = true;
             foreach ((array) $task->get($type) as $name) {
                 if ($name === '@self') {
                     $name = $this->get('name');
                 }
                 $key = $type . ':' . $name;
                 $this->job->deferredTasks[$key][] = $task;
             }
         }
     }
     if ($this->initialized || $deferred) {
         $task->initialize();
     }
     if (!$deferred && $this->started) {
         return $this->runTask($task);
     }
     if (!$deferred) {
         $this->tasks[] = $task;
     }
     return $this;
 }