Example #1
0
 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);
 }
Example #2
0
 public function testParseRouteDeclarationWithPrefixes()
 {
     $parser = new Parser();
     $endpoint = new Endpoint();
     Endpoint::pushPrefix('v1');
     // GET
     $parser->parseRouteDeclaration($endpoint, "Route::get('resources/{resource}', 'ResourceController@show');");
     $this->assertEquals('GET', $endpoint->getMethod());
     $this->assertEquals('/v1/resources/{resource}', $endpoint->getPath());
 }
Example #3
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');
 }