示例#1
0
 /**
  * Set a variable and it's value
  *
  * @param string $name  The variable name
  * @param mixed  $value The value
  *
  * @return $this
  */
 public function offsetSet($name, $value)
 {
     if ($name === 'expression') {
         $this->expression = $value;
     }
     parent::offsetSet($name, $value);
 }
示例#2
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;
 }
示例#3
0
 /**
  * Show an information of what will happen
  *
  * @return void
  */
 public function preview()
 {
     parent::preview();
     $fn = $this->get('callback');
     if (is_string($fn)) {
         $name = $fn;
     } elseif (is_array($fn)) {
         $name = (is_object($fn[0]) ? get_class($fn[0]) . '->' : $fn[0] . '::') . $fn[1];
     } else {
         $name = 'anonymous function';
     }
     $this->console->output('Calling ' . $name, OutputInterface::VERBOSITY_DEBUG);
 }
示例#4
0
文件: Job.php 项目: netresearch/kite
 /**
  * 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);
         }
     }
 }
示例#5
0
 /**
  * Configures the available options
  *
  * @return array
  */
 protected function configureVariables()
 {
     return array('from' => array('type' => 'string', 'required' => true, 'label' => 'The path to the directory to create the phar from'), 'to' => array('type' => 'string', 'required' => true, 'label' => 'Path and filename of the resulting phar file'), 'filter' => array('type' => 'string', 'label' => 'Only file paths matching this pcre regular expression will be included in the archive'), 'cliStub' => array('type' => 'string', 'label' => 'Path to cli index file, relative to <info>comment</info>'), 'webStub' => array('type' => 'string', 'label' => 'Path to web index file, relative to <info>comment</info>'), 'alias' => array('type' => 'string', 'label' => 'Alias with which this Phar archive should be referred to in calls to stream functionality'), 'metadata' => array('type' => 'mixed', 'label' => 'Anything containing information to store that describes the phar archive')) + parent::configureVariables();
 }
示例#6
0
 /**
  * Configure the options
  *
  * @return array
  */
 protected function configureVariables()
 {
     return array('file' => array('type' => 'string', 'required' => 'true', 'label' => 'The file to include'), '--') + parent::configureVariables();
 }
示例#7
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;
 }
示例#8
0
 /**
  * Configure the options
  *
  * @return array
  */
 protected function configureVariables()
 {
     return array('code' => array('type' => 'int', 'default' => 0, 'label' => 'Code to exit with'), '--') + parent::configureVariables();
 }
示例#9
0
 /**
  * Handle arguments, options and optArg
  *
  * @param string $option Option name
  * @param mixed  $value  Option value
  *
  * @return void
  */
 public function offsetSet($option, $value)
 {
     if ($option === 'processSettings') {
         $value = array_merge($this->offsetGet('processSettings'), $value);
     }
     if (in_array($option, array('arguments', 'options', 'optArg'), true)) {
         if ($value === null) {
             if ($option === 'optArg' || $option === 'options') {
                 parent::offsetSet('options', array());
             }
             if ($option === 'optArg' || $option === 'arguments') {
                 parent::offsetSet('arguments', array());
             }
             return;
         }
         if ($option === 'optArg' && is_string($value)) {
             parent::offsetSet('argv', $value);
             return;
         }
         $arguments = $this->get('arguments');
         $options = $this->get('options');
         if ($option == 'arguments') {
             $arguments = array_merge($arguments, $value);
         } elseif ($option == 'options') {
             foreach ($value as $k => $v) {
                 if (is_numeric($k)) {
                     $options[$v] = true;
                 } else {
                     $options[$k] = $v;
                 }
             }
         } elseif ($option == 'optArg') {
             foreach ($value as $k => $v) {
                 if (is_numeric($k)) {
                     $arguments[] = $v;
                 } else {
                     $options[$k] = $v;
                 }
             }
         }
         parent::offsetSet('arguments', $arguments);
         parent::offsetSet('options', $options);
         return;
     }
     parent::offsetSet($option, $value);
 }
示例#10
0
 /**
  * Configure the options
  *
  * @return array
  */
 protected function configureVariables()
 {
     return array('action' => array('type' => 'string', 'required' => true, 'label' => 'Method of \\Netresearch\\Kite\\Service\\Filesystem to execute'), 'arguments' => array('type' => 'array', 'default' => array(), 'label' => 'Arguments for action method')) + parent::configureVariables();
 }
示例#11
0
 /**
  * Configure the variables
  *
  * @return array
  */
 protected function configureVariables()
 {
     return array('question' => array('type' => 'string', 'required' => true, 'label' => 'The question to ask'), 'default' => array('type' => 'string|numeric', 'label' => 'Default value (shown to the user as well)'), '--') + parent::configureVariables();
 }
示例#12
0
 /**
  * Configure the options
  *
  * @return array
  */
 protected function configureVariables()
 {
     return array('command' => array('type' => 'string', 'label' => 'Name of the task', 'required' => true), 'cwd' => array('type' => 'string', 'label' => 'The directory to change to before running the command'), 'options' => array('type' => 'array', 'default' => array(), 'label' => 'Array with options: Elements with numeric keys or bool true values will be --switches.'), 'arguments' => array('type' => 'array', 'default' => array(), 'label' => 'Arguments to pass to the cmd'), 'optArg' => array('type' => 'array', 'label' => 'Arguments and options in one array. Elements with numeric keys will be arguments, elems. with bool true values will be --switches, all other options')) + parent::configureVariables();
 }