示例#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
 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
 /**
  * @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);
     }
 }