Beispiel #1
0
 public function __call($name, $params)
 {
     if (isset($this->_registered[$name])) {
         $closure = $this->_registered[$name];
     } else {
         $this->_namespace[] = $name;
         $fn = implode('/', $this->_namespace);
         $this->_namespace = null;
         if (!($fullname = $this->resolve($fn))) {
             throw new Exception("can't locate {$fn} in {$this->_path}");
         }
         $closure = Reflection::getClosure($fullname);
     }
     if ($this->_context) {
         $closure = $closure->bindTo($this->_context);
     }
     return call_user_func_array($closure, $params);
 }
Beispiel #2
0
 public function help()
 {
     $buffer[] = "Usage:\n";
     foreach ($this->rules as $rule) {
         list($pattern, $handler, $module) = $rule;
         $buffer[] = "  php {$_SERVER['argv'][0]} {$pattern}";
         $params = array_filter(Reflection::parseDoc($handler), function ($doc) {
             return $doc[0] === 'param';
         });
         $lines = array_map(function ($param) use($pattern) {
             list($type, $name, $comment) = explode(' ', $param[1], 3);
             $name = ltrim($name, '$');
             if (false === strpos($pattern, "<{$name}>")) {
                 $name = '--' . implode('-', array_map('lcfirst', preg_split('/(?=[A-Z])/', $name)));
             }
             return [$name, $comment];
         }, $params);
         foreach ($this->column($lines) as $line) {
             $buffer[] = "      {$line}";
         }
         $buffer[] = '';
     }
     return implode("\n", $buffer);
 }
Beispiel #3
0
 private function processDocString($handler)
 {
     $doc = Reflection::parseDoc($handler);
     $middlewares = [];
     foreach ($doc as $item) {
         list($key, $value) = $item;
         $middlewares[] = [$key, explode(',', $value)];
     }
     return $middlewares;
 }
Beispiel #4
0
 public function testParameters()
 {
     $closure = function ($foo, $bar = null) {
     };
     $this->assertEquals(count(Reflection::parameters($closure)), 2);
 }