mageekguy\atoum\script\arguments\parser::addHandler PHP Method

addHandler() public method

public addHandler ( closure $handler, array $arguments, $priority )
$handler closure
$arguments array
    public function addHandler(\closure $handler, array $arguments, $priority = 0)
    {
        $invoke = new \reflectionMethod($handler, '__invoke');
        if ($invoke->getNumberOfParameters() < 3) {
            throw new exceptions\runtime('Handler must take three arguments');
        }
        foreach ($arguments as $argument) {
            if (self::isArgument($argument) === false) {
                throw new exceptions\runtime('Argument \'' . $argument . '\' is invalid');
            }
            $this->handlers[$argument][] = $handler;
            $this->priorities[$argument] = (int) $priority;
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testResetHandlers()
 {
     $this->assert->if($parser = new script\arguments\parser())->then->object($parser->resetHandlers())->isIdenticalTo($parser)->array($parser->getHandlers())->isEmpty()->array($parser->getPriorities())->isEmpty()->if($parser->addHandler(function ($script, $argument, $values) {
     }, array('-a')))->then->object($parser->resetHandlers())->isIdenticalTo($parser)->array($parser->getHandlers())->isEmpty()->array($parser->getPriorities())->isEmpty();
 }