diff --git a/src/Implementations/Composer.php b/src/Implementations/Composer.php deleted file mode 100644 index 2e59c01..0000000 --- a/src/Implementations/Composer.php +++ /dev/null @@ -1,26 +0,0 @@ - "3.0.1", - "info"=> [ - "title"=> "unknown", - "version"=> "1.0.0" - ] - ]; - /** * Generates an overview over routes registered * @return-200 application/json {"type":"object"} @@ -38,17 +23,16 @@ public function index(): ResponseInterface foreach ($this->router->getRoutes() as $route) { $paths[] = $converter->convert($route); } - $merger = $this->di->get(RecursiveMerger::class); return $this ->getCorsEnabledResponse() ->setJsonContent( - $merger->merge( - self::$body, - [ - 'paths' => $merger->mergeAll(...$paths), - 'info' => (new Composer())(dirname(__DIR__, 5).'/composer.json') + [ + 'paths' => $this->di->get(RMI::class)->mergeAll(...$paths), + 'info' => [ + "title"=> Versions::ROOT_PACKAGE_NAME, + "version"=> Versions::getVersion(Versions::ROOT_PACKAGE_NAME) ] - ) + ] ); } @@ -96,14 +80,4 @@ private function getCorsEnabledResponse(): ResponseInterface ) ->setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS'); } - - /** - * @param string $root - * @return ControllerInterface - */ - public function setRoot(string $root): ControllerInterface - { - $this->root = $root; - return $this; - } } diff --git a/src/Implementations/DefaultResponse.php b/src/Implementations/DefaultResponse.php index 2d26b94..a43829f 100644 --- a/src/Implementations/DefaultResponse.php +++ b/src/Implementations/DefaultResponse.php @@ -1,4 +1,4 @@ -checkArray(array_shift($sets), 1); + $initial = array_shift($sets); foreach ($sets as $pos => $set) { - $initial = $this->merge($initial, $this->checkArray($set, $pos+2)); + $initial = $this->merge($initial, $set); } return $initial; } - - /** - * @param mixed $set - * @param int $num - * @throws InvalidArgumentException - * @return array - */ - private function checkArray($set, int $num): array - { - if (!is_array($set)) { - throw new InvalidArgumentException("Set #$num is not an array, but a(n) " . gettype($set) . '.'); - } - return $set; - } } diff --git a/src/Implementations/PhalconPath2PathArray.php b/src/Implementations/PhalconPath2PathArray.php index 151afd4..8debc89 100644 --- a/src/Implementations/PhalconPath2PathArray.php +++ b/src/Implementations/PhalconPath2PathArray.php @@ -1,4 +1,4 @@ -cache[$class])) { - $this->cache[$class]['____class'] = new ReflectionClass($class); + $this->cache[$class]['#'] = new ReflectionClass($class); } if (!isset($this->cache[$class][$method])) { $this->cache[$class][$method] = DefaultResponse::add( - $this->getReflect($this->cache[$class]['____class'], $method) + $this->getReflect($this->cache[$class]['#'], $method) ); } } catch (Exception $e) { diff --git a/src/Interfaces/Controller.php b/src/Interfaces/Controller.php index 6e9e81a..6b14da1 100644 --- a/src/Interfaces/Controller.php +++ b/src/Interfaces/Controller.php @@ -1,4 +1,4 @@ -apiRoot = ($apiRoot{0}==='/' ? '' : '/') . $apiRoot; - } - /** * Registers controller at api-root * @param DiInterface $serviceContainer @@ -33,7 +25,7 @@ public function __construct(string $apiRoot = '/') */ public function register(DiInterface $serviceContainer) { - $this->registerServices($serviceContainer, $this->apiRoot); + $this->registerServices($serviceContainer); $this->registerRoutes($serviceContainer->get('router')); } @@ -42,10 +34,10 @@ public function register(DiInterface $serviceContainer) * @param string $root * @return void */ - private function registerServices(DiInterface $serviceContainer, string $root) + private function registerServices(DiInterface $serviceContainer) { - $serviceContainer->set(Controller::class, function () use ($root) { - return (new ControllerImplementation())->setRoot($root); + $serviceContainer->set(Controller::class, function () { + return (new ControllerImplementation()); }); $serviceContainer->set(Path2PathConverter::class, function () use (&$serviceContainer) { return new PhalconPath2PathArray( diff --git a/test/ComposerTest.php b/test/ComposerTest.php deleted file mode 100644 index af3ecde..0000000 --- a/test/ComposerTest.php +++ /dev/null @@ -1,25 +0,0 @@ - "idrinth/phalcon-routes2openapi", - "description" => "Generates an JSON represantation of the routes " - . "registered via phalcon in an OpenAPI-compatible way." - ], - (new Composer())(dirname(__DIR__).'/composer.json') - ); - } -} diff --git a/test/ControllerTest.php b/test/ControllerTest.php index 69d62ae..0f2f00d 100644 --- a/test/ControllerTest.php +++ b/test/ControllerTest.php @@ -36,7 +36,6 @@ public function provideIndex(): array return [ [ $this->buildRouterMock(), - '/', [ "openapi" => "3.0.1", "info" => [ @@ -52,7 +51,6 @@ public function provideIndex(): array ], [ $this->buildRouterMock(), - '/hi/', [ "openapi" => "3.0.1", "info" => [ @@ -76,11 +74,9 @@ public function provideOptions(): array { return [ [ - '/', '', ], [ - '/', 'http://abc.de', ], ]; @@ -88,14 +84,12 @@ public function provideOptions(): array /** * @param DiInterface $serviceContainer - * @param string $root * @return Controller */ - private function getBasePreparedInstance(DiInterface $serviceContainer, string $root): Controller + private function getBasePreparedInstance(DiInterface $serviceContainer): Controller { $instance = new Controller(); $instance->request = $this->getMockBuilder(RequestInterface::class)->getMock(); - $instance->setRoot($root); $instance->setDI($serviceContainer); $instance->response = $this->getMockBuilder(ResponseInterface::class)->getMock(); $instance->response->expects(static::exactly(2)) @@ -106,11 +100,10 @@ private function getBasePreparedInstance(DiInterface $serviceContainer, string $ /** * @param RouterInterface $router - * @param string $root * @param array $result * @return Controller */ - private function getPreparedInstance(RouterInterface $router, string $root, array $result): Controller + private function getPreparedInstance(RouterInterface $router, array $result): Controller { $serviceContainer = $this->getMockBuilder(DiInterface::class)->getMock(); $p2p = $this->getMockBuilder(Path2PathConverter::class)->getMock(); @@ -157,7 +150,7 @@ private function getPreparedInstance(RouterInterface $router, string $root, arra [RecursiveMerger::class] ) ->willReturnOnConsecutiveCalls($p2p, $merger); - $instance = $this->getBasePreparedInstance($serviceContainer, $root); + $instance = $this->getBasePreparedInstance($serviceContainer); $instance->router = $router; $instance->response->expects(static::once()) ->method('setJsonContent') @@ -170,13 +163,12 @@ private function getPreparedInstance(RouterInterface $router, string $root, arra * @test * @dataProvider provideIndex * @param RouterInterface $router - * @param string $root * @param array $result * @return void */ - public function testIndex(RouterInterface $router, string $root, array $result) + public function testIndex(RouterInterface $router, array $result) { - $instance = $this->getPreparedInstance($router, $root, $result); + $instance = $this->getPreparedInstance($router, $result); static::assertSame($instance->response, $instance->index()); } @@ -184,13 +176,12 @@ public function testIndex(RouterInterface $router, string $root, array $result) * @test * @dataProvider provideIndex * @param RouterInterface $router - * @param string $root * @param array $result * @return void */ - public function testIndexAction(RouterInterface $router, string $root, array $result) + public function testIndexAction(RouterInterface $router, array $result) { - $instance = $this->getPreparedInstance($router, $root, $result); + $instance = $this->getPreparedInstance($router, $result); static::assertSame($instance->response, $instance->indexAction()); } @@ -220,16 +211,16 @@ private function prepareInstanceForOptions(Controller $instance, string $origin) ) ->willReturnSelf(); } + /** * @test * @dataProvider provideOptions - * @param string $root * @param string $origin * @return void */ - public function testOptions(string $root, string $origin) + public function testOptions(string $origin) { - $instance = $this->getBasePreparedInstance($this->getMockBuilder(DiInterface::class)->getMock(), $root); + $instance = $this->getBasePreparedInstance($this->getMockBuilder(DiInterface::class)->getMock()); $this->prepareInstanceForOptions($instance, $origin); static::assertSame($instance->response, $instance->options()); } @@ -237,13 +228,12 @@ public function testOptions(string $root, string $origin) /** * @test * @dataProvider provideOptions - * @param string $root * @param string $origin * @return void */ - public function testOptionsAction(string $root, string $origin) + public function testOptionsAction(string $origin) { - $instance = $this->getBasePreparedInstance($this->getMockBuilder(DiInterface::class)->getMock(), $root); + $instance = $this->getBasePreparedInstance($this->getMockBuilder(DiInterface::class)->getMock()); $this->prepareInstanceForOptions($instance, $origin); static::assertSame($instance->response, $instance->optionsAction()); }