コード例 #1
0
ファイル: FredSpec.php プロジェクト: wouterj/fred
 function it_accepts_nested_tasks(TaskStack $stack)
 {
     $stack->push(Argument::that(function ($task) {
         return $task->getName() === 'build' && $task->getDependencies() === array('test', 'minify', 'cleanup');
     }));
     $this->task('build', array('test', 'minify', 'cleanup'));
 }
コード例 #2
0
ファイル: TaskStackSpec.php プロジェクト: wouterj/fred
 function it_merges_stacks(TaskStack $stack, Task $task4, Task $task5)
 {
     $task4->getDependencies()->willReturn(array());
     $task5->getDependencies()->willReturn(array());
     $task4->getName()->willReturn('task4');
     $task5->getName()->willReturn('task5');
     $stack->getIterator()->willReturn(new \ArrayIterator(array($task4->getWrappedObject(), $task5->getWrappedObject())));
     $this->merge($stack);
     $this->has('task4')->shouldReturn(true);
     $this->has('task5')->shouldReturn(true);
 }
コード例 #3
0
ファイル: TaskStack.php プロジェクト: wouterj/fred
 /**
  * @return TaskStack
  */
 public function getStackForTask($name)
 {
     if (!$this->has($name)) {
         throw new TaskNotFoundException($name);
     }
     $stack = new TaskStack();
     $task = $this->tasks[$name];
     foreach ($task->getDependencies() as $dep) {
         $stack->merge($this->getStackForTask($dep), true);
     }
     $stack->push($task);
     return $stack;
 }
コード例 #4
0
ファイル: Fred.php プロジェクト: wouterj/fred
 /**
  * Executes a task.
  */
 public function execute($name, array $arguments = array())
 {
     $stack = $this->taskStack->getStackForTask($name);
     if (0 === count($stack)) {
         throw new TaskNotFoundException($name);
     }
     foreach ($stack as $task) {
         $callable = $task->getTask();
         $callableReflection = new \ReflectionFunction($callable);
         $callableArguments = array();
         foreach ($callableReflection->getParameters() as $parameter) {
             $name = $parameter->getName();
             if (isset($arguments[$name])) {
                 $callableArguments[] = $arguments[$name];
             } elseif ($parameter->isOptional()) {
                 $callableArguments[] = $parameter->getDefaultValue();
             } else {
                 throw new MissingArgumentsException($task->getName(), $task->getSynopsis());
             }
         }
         return call_user_func_array($callable, $callableArguments);
     }
 }