コード例 #1
0
ファイル: Parser.php プロジェクト: TadasPaplauskas/apidocs
 public function parseEndpoints()
 {
     $lines = $this->getLines();
     if (empty($lines)) {
         return 'Something\'s wrong with routing files.';
     }
     $documentedEndpoints = [];
     $endpoint = null;
     // iterate through array with pointer functions
     // foreach would introduce unwanted complications here
     reset($lines);
     while ($line = next($lines)) {
         // we have found the beginning of a new docblock
         if (!$endpoint && $this->firstLineOfDocBlock($line)) {
             $endpoint = new Endpoint();
         } elseif ($endpoint && $this->lastLineOfDocBlock($line)) {
             // route declaration is expected to be on the next line
             $this->parseRouteDeclaration($endpoint, next($lines));
             // store it for display and close
             array_push($documentedEndpoints, $endpoint);
             $endpoint = null;
         } elseif ($endpoint && $this->insideDocBlock($line)) {
             $this->parseTags($endpoint, $line);
         } elseif (!$endpoint && ($prefix = $this->parsePrefix($line))) {
             Endpoint::pushPrefix($prefix);
         } elseif (!$endpoint && str_contains($line, '});')) {
             Endpoint::popPrefix();
         }
     }
     return $this->groupEndpoints($documentedEndpoints);
 }
コード例 #2
0
 /**
  * @runInSeparateProcess
  */
 public function testSetPathWithPrefixes()
 {
     $endpoint = new Endpoint();
     Endpoint::pushPrefix('v1');
     $endpoint->setPath('resource');
     $this->assertEquals($endpoint->getPath(), '/v1/resource');
     Endpoint::popPrefix();
     $endpoint->setPath('dummy');
     $this->assertEquals($endpoint->getPath(), '/dummy');
 }