Beispiel #1
0
 public function testParseDoc()
 {
     /**
      * @param string $foo more doc
      * @param string $bar
      * @permission all
      */
     $closure = function () {
     };
     $this->assertSame(Reflection::parseDoc($closure), [['param', 'string $foo more doc'], ['param', 'string $bar'], ['permission', 'all']]);
 }
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;
 }