public function onGet() { parent::onGet(); $links = []; $apiPath = $this->reverseRouter->getDispatchUrl(); if ($apiPath !== null) { $links[] = new Object(['rel' => 'api', 'href' => $apiPath]); } $routingPath = $this->reverseRouter->getUrl('PSX\\Controller\\Tool\\RoutingController'); if ($routingPath !== null) { $links[] = new Object(['rel' => 'routing', 'href' => $routingPath]); } $commandPath = $this->reverseRouter->getUrl('PSX\\Controller\\Tool\\CommandController'); if ($commandPath !== null) { $links[] = new Object(['rel' => 'command', 'href' => $commandPath]); } $documentationPath = $this->reverseRouter->getUrl('PSX\\Controller\\Tool\\DocumentationController::doIndex'); if ($documentationPath !== null) { $links[] = new Object(['rel' => 'documentation', 'href' => $documentationPath]); } $ramlGeneratorPath = $this->reverseRouter->getUrl('PSX\\Controller\\Tool\\RamlGeneratorController', ['{version}', '{path}']); if ($ramlGeneratorPath !== null) { $links[] = new Object(['rel' => 'raml', 'href' => $ramlGeneratorPath]); } $wsdlGeneratorPath = $this->reverseRouter->getUrl('PSX\\Controller\\Tool\\WsdlGeneratorController', ['{version}', '{path}']); if ($wsdlGeneratorPath !== null) { $links[] = new Object(['rel' => 'wsdl', 'href' => $wsdlGeneratorPath]); } $swaggerGeneratorPath = $this->reverseRouter->getUrl('PSX\\Controller\\Tool\\SwaggerGeneratorController::doDetail', ['{version}', '{path}']); if ($swaggerGeneratorPath !== null) { $links[] = new Object(['rel' => 'swagger', 'href' => $swaggerGeneratorPath]); } $this->setBody(['links' => $links]); }
/** * Throws an redirect exception which sends an Location header. If source is * not an url the reverse router is used to determine the url * * @param string $source * @param array $parameters * @param integer $code */ protected function redirect($source, array $parameters = array(), $code = 307) { if ($source instanceof Url) { $url = $source->toString(); } elseif (filter_var($source, FILTER_VALIDATE_URL)) { $url = $source; } else { $url = $this->reverseRouter->getUrl($source, $parameters); } if ($code == 301) { throw new StatusCode\MovedPermanentlyException($url); } else { if ($code == 302) { throw new StatusCode\FoundException($url); } else { if ($code == 307) { throw new StatusCode\TemporaryRedirectException($url); } else { throw new RuntimeException('Invalid redirect status code'); } } } }
protected function getSeeOthers($version, $path) { $path = ltrim($path, '/'); $result = new \stdClass(); $wsdlGeneratorPath = $this->reverseRouter->getAbsolutePath('PSX\\Controller\\Tool\\WsdlGeneratorController', array('version' => $version, 'path' => $path)); if ($wsdlGeneratorPath !== null) { $result->WSDL = $wsdlGeneratorPath; } $swaggerGeneratorPath = $this->reverseRouter->getAbsolutePath('PSX\\Controller\\Tool\\SwaggerGeneratorController::doDetail', array('version' => $version, 'path' => $path)); if ($swaggerGeneratorPath !== null) { $result->Swagger = $swaggerGeneratorPath; } $ramlGeneratorPath = $this->reverseRouter->getAbsolutePath('PSX\\Controller\\Tool\\RamlGeneratorController', array('version' => $version, 'path' => $path)); if ($ramlGeneratorPath !== null) { $result->RAML = $ramlGeneratorPath; } return $result; }
public function testGetUrl() { $routingFile = new RoutingFile('tests/PSX/Loader/routes'); $router = new ReverseRouter($routingFile, 'http://foo.com', ''); $this->assertEquals('http://foo.com/foo/bar', $router->getUrl('PSX\\Loader\\Foo2Controller')); $routingFile = new RoutingFile('tests/PSX/Loader/routes'); $router = new ReverseRouter($routingFile, 'http://foo.com/foo/bar', ''); $this->assertEquals('http://foo.com/foo/bar/foo/bar', $router->getUrl('PSX\\Loader\\Foo2Controller')); $routingFile = new RoutingFile('tests/PSX/Loader/routes'); $router = new ReverseRouter($routingFile, 'http://foo.com/foo/bar', 'index.php/'); $this->assertEquals('http://foo.com/foo/bar/index.php/foo/bar', $router->getUrl('PSX\\Loader\\Foo2Controller')); $routingFile = new RoutingFile('tests/PSX/Loader/routes'); $router = new ReverseRouter($routingFile, 'http://foo.com', ''); $this->assertEquals('http://cdn.foo.com/files/foo/common.js', $router->getUrl('PSX\\Loader\\Foo13Controller', array('path' => 'foo/common.js'))); }