Example #1
0
 public function render()
 {
     $handlers = $this->apiDecider->getHandlers();
     $this->getTemplate()->add('handlers', $this->sortHandlers($handlers));
     $this->getTemplate()->setFile(__DIR__ . '/api_listing.latte');
     $this->getTemplate()->render();
 }
Example #2
0
 /**
  * Create handler list for specified version
  *
  * @param integer $version
  *
  * @return array
  */
 private function getHandlersList($version)
 {
     $versionHandlers = array_filter($this->apiDecider->getHandlers(), function ($handler) use($version) {
         return $version == $handler['endpoint']->getVersion();
     });
     return array_map(function ($handler) {
         return ['method' => $handler['endpoint']->getMethod(), 'version' => $handler['endpoint']->getVersion(), 'package' => $handler['endpoint']->getPackage(), 'api_action' => $handler['endpoint']->getApiAction(), 'authorization' => get_class($handler['authorization']), 'url' => $this->apiLink->link($handler['endpoint']), 'params' => $this->createParamsList($handler['handler'])];
     }, $versionHandlers);
 }
Example #3
0
 public function testGlobalPreflight()
 {
     $linkGenerator = new LinkGenerator(new SimpleRouter([]), new Url('http://test/'));
     $apiLink = new ApiLink($linkGenerator);
     $apiDecider = new ApiDecider($apiLink);
     $apiDecider->enableGlobalPreflight();
     $this->assertEquals(0, count($apiDecider->getHandlers()));
     $apiDecider->addApiHandler(new EndpointIdentifier('POST', 2, 'comments', 'list'), new AlwaysOkHandler(), new NoAuthorization());
     $this->assertEquals(1, count($apiDecider->getHandlers()));
     $handler = $apiDecider->getApiHandler('OPTIONS', 2, 'comments', 'list');
     $this->assertInstanceOf('Tomaj\\NetteApi\\Handlers\\CorsPreflightHandler', $handler['handler']);
 }