From a900a28c43c5ca7f972fc5d6afe7ea623f7358e0 Mon Sep 17 00:00:00 2001 From: Alexandre Lemaire Date: Thu, 3 Nov 2016 21:51:36 -0400 Subject: [PATCH 1/7] forgot a comma in examples --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e07275..530cf88 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ On any action in a controller with the use statement, use these types of annotat /** * Route with parameter, name, constraint, and defaults - * @Route("/freedom/:param", name="easy-as-pie" constraints={"param":"[a-zA-Z]"}, defaults={"param":"index"}) + * @Route("/freedom/:param", name="easy-as-pie", constraints={"param":"[a-zA-Z]"}, defaults={"param":"index"}) */ public function anyOldNameAction(){ // ... From 2d0ebd9b965353f001c9b5fd5bae5206aae1b2ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Makaruk?= Date: Thu, 10 Nov 2016 23:00:59 +0100 Subject: [PATCH 2/7] Either author wanted to use AnnotationReader::getMethodAnnotation (note missing s) or if more than one route per action should be available there is a missing validation that current annotation is instance of CirclicalAutoWire\Annotations\Route --- src/CirclicalAutoWire/Service/RouterService.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/CirclicalAutoWire/Service/RouterService.php b/src/CirclicalAutoWire/Service/RouterService.php index 6279102..07ba0cb 100644 --- a/src/CirclicalAutoWire/Service/RouterService.php +++ b/src/CirclicalAutoWire/Service/RouterService.php @@ -51,6 +51,7 @@ public function reset() public function parseController(string $controllerClass) { $class = new \ReflectionClass($controllerClass); + /** @var Route $classAnnotation */ $classAnnotation = $this->reader->getClassAnnotation($class, Route::class); // First, get all annotations for this controller @@ -58,9 +59,13 @@ public function parseController(string $controllerClass) /** @var \ReflectionMethod $method */ foreach ($class->getMethods() as $method) { if ($method->getDeclaringClass()->getName() == $controllerClass) { - $set = $this->reader->getMethodAnnotations($method, Route::class); + $set = $this->reader->getMethodAnnotations($method); /** @var Route $routerAnnotation */ foreach ($set as $routerAnnotation) { + if (!$routerAnnotation instanceof Route) { + continue; + } + if ($classAnnotation) { $routerAnnotation->setPrefix($classAnnotation->value); } From e7ec654814d583ed23e9f15dff9c11a2418de15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Makaruk?= Date: Fri, 11 Nov 2016 19:55:12 +0100 Subject: [PATCH 3/7] Prepared some test, I'm not really familiar with phpspec, hope this will help --- .../Annotations/OtherAnnotation.php | 21 ++++++++++++ .../Controller/OtherAnnotationsController.php | 32 +++++++++++++++++++ .../OtherAnnotationsTypeErrorController.php | 24 ++++++++++++++ .../Service/RouterServiceSpec.php | 23 ++++++++++++- 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 bundle/Spec/CirclicalAutoWire/Annotations/OtherAnnotation.php create mode 100644 bundle/Spec/CirclicalAutoWire/Controller/OtherAnnotationsController.php create mode 100644 bundle/Spec/CirclicalAutoWire/Controller/OtherAnnotationsTypeErrorController.php diff --git a/bundle/Spec/CirclicalAutoWire/Annotations/OtherAnnotation.php b/bundle/Spec/CirclicalAutoWire/Annotations/OtherAnnotation.php new file mode 100644 index 0000000..8197bb3 --- /dev/null +++ b/bundle/Spec/CirclicalAutoWire/Annotations/OtherAnnotation.php @@ -0,0 +1,21 @@ + + * + * @Annotation + * @Target({"METHOD","CLASS"}) + */ +final class OtherAnnotation +{ + /** + * @var string + */ + public $value; + +} diff --git a/bundle/Spec/CirclicalAutoWire/Controller/OtherAnnotationsController.php b/bundle/Spec/CirclicalAutoWire/Controller/OtherAnnotationsController.php new file mode 100644 index 0000000..475a74d --- /dev/null +++ b/bundle/Spec/CirclicalAutoWire/Controller/OtherAnnotationsController.php @@ -0,0 +1,32 @@ +parseController(SameNameBController::class); $this->compile(); } -} \ No newline at end of file + + function it_skips_other_annotations($routerStack) + { + include __DIR__ . '/../../CirclicalAutoWire/Controller/OtherAnnotationsController.php'; + AnnotationRegistry::registerAutoloadNamespace("Spec\\CirclicalAutoWire\\Annotations", realpath(__DIR__ . "/../../../")); + + $this->shouldNotThrow(\Error::class)->during('parseController', [OtherAnnotationsController::class]); + } + + function it_skips_other_annotations_type_error($routerStack) + { + include __DIR__ . '/../../CirclicalAutoWire/Controller/OtherAnnotationsTypeErrorController.php'; + AnnotationRegistry::registerAutoloadNamespace("Spec\\CirclicalAutoWire\\Annotations", realpath(__DIR__ . "/../../../")); + + //this should be thrown, but I'm unable to force it... +// $this->shouldThrow(\TypeError::class)->during('parseController', [OtherAnnotationsTypeErrorController::class]); + $this->shouldNotThrow(\PhpSpec\Exception\Example\ErrorException::class)->during('parseController', [OtherAnnotationsTypeErrorController::class]); + } +} From 4b9e07792fcd997f24f5b4fe97101c9330ae6545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Makaruk?= Date: Fri, 11 Nov 2016 20:03:32 +0100 Subject: [PATCH 4/7] fixed usunsed method variables --- bundle/Spec/CirclicalAutoWire/Service/RouterServiceSpec.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/Spec/CirclicalAutoWire/Service/RouterServiceSpec.php b/bundle/Spec/CirclicalAutoWire/Service/RouterServiceSpec.php index ad60219..81fc164 100644 --- a/bundle/Spec/CirclicalAutoWire/Service/RouterServiceSpec.php +++ b/bundle/Spec/CirclicalAutoWire/Service/RouterServiceSpec.php @@ -225,7 +225,7 @@ function it_lets_children_have_same_names($routeStack) $this->compile(); } - function it_skips_other_annotations($routerStack) + function it_skips_other_annotations() { include __DIR__ . '/../../CirclicalAutoWire/Controller/OtherAnnotationsController.php'; AnnotationRegistry::registerAutoloadNamespace("Spec\\CirclicalAutoWire\\Annotations", realpath(__DIR__ . "/../../../")); @@ -233,7 +233,7 @@ function it_skips_other_annotations($routerStack) $this->shouldNotThrow(\Error::class)->during('parseController', [OtherAnnotationsController::class]); } - function it_skips_other_annotations_type_error($routerStack) + function it_skips_other_annotations_type_error() { include __DIR__ . '/../../CirclicalAutoWire/Controller/OtherAnnotationsTypeErrorController.php'; AnnotationRegistry::registerAutoloadNamespace("Spec\\CirclicalAutoWire\\Annotations", realpath(__DIR__ . "/../../../")); From 9be00383b0d5edafb5a0822b0117f24070846703 Mon Sep 17 00:00:00 2001 From: buliq Date: Mon, 27 Feb 2017 01:41:23 +0100 Subject: [PATCH 5/7] If file not exists in production mode - generate it anyway --- src/CirclicalAutoWire/Module.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CirclicalAutoWire/Module.php b/src/CirclicalAutoWire/Module.php index 3b5d409..0a03db6 100644 --- a/src/CirclicalAutoWire/Module.php +++ b/src/CirclicalAutoWire/Module.php @@ -59,7 +59,7 @@ public function onBootstrap(MvcEvent $mvcEvent) $config = $serviceLocator->get('config'); $productionMode = Console::isConsole() || $config['circlical']['autowire']['production_mode']; - if (!$productionMode) { + if (!$productionMode || !file_exists($config['circlical']['autowire']['compile_to'])) { $routerService = $serviceLocator->get(RouterService::class); $directoryScanner = new DirectoryScanner(); @@ -85,4 +85,4 @@ public function onBootstrap(MvcEvent $mvcEvent) $routerService->reset(); } } -} \ No newline at end of file +} From 450b4697f2e8fa44f5b80e57fe0572fdd58f1c77 Mon Sep 17 00:00:00 2001 From: buliq Date: Mon, 27 Feb 2017 03:17:23 +0100 Subject: [PATCH 6/7] Update AnnotatedRoute.php --- src/CirclicalAutoWire/Model/AnnotatedRoute.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CirclicalAutoWire/Model/AnnotatedRoute.php b/src/CirclicalAutoWire/Model/AnnotatedRoute.php index ab90b64..5ad2c60 100644 --- a/src/CirclicalAutoWire/Model/AnnotatedRoute.php +++ b/src/CirclicalAutoWire/Model/AnnotatedRoute.php @@ -44,7 +44,7 @@ public function __construct(Route $route, string $controller, string $action) public function toArray(): array { $route = [ - 'type' => $this->type ?? $this->identifyRoute($this->route->value), + 'type' => $this->type ?? $this->route->type ?? $this->identifyRoute($this->route->value), 'options' => [ 'route' => $this->route->value, 'defaults' => [ @@ -85,4 +85,4 @@ private function identifyRoute(string $route): string return Literal::class; } -} \ No newline at end of file +} From 4274f1568730a1587f1028b4b7f72d3a5df43b3e Mon Sep 17 00:00:00 2001 From: buliq Date: Wed, 1 Mar 2017 08:17:01 +0100 Subject: [PATCH 7/7] Update Module.php --- src/CirclicalAutoWire/Module.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CirclicalAutoWire/Module.php b/src/CirclicalAutoWire/Module.php index 0a03db6..382fe9b 100644 --- a/src/CirclicalAutoWire/Module.php +++ b/src/CirclicalAutoWire/Module.php @@ -83,6 +83,12 @@ public function onBootstrap(MvcEvent $mvcEvent) $writer = new PhpArray(); $writer->toFile($config['circlical']['autowire']['compile_to'], $routeConfig, true); $routerService->reset(); + + /** @var \Zend\ModuleManager\Listener\ConfigListener $cfg */ + $cfg = $serviceLocator->get(\Zend\ModuleManager\ModuleManager::class)->getEvent()->getConfigListener(); + if ($productionMode && $cfg->getOptions()->getConfigCacheEnabled() && file_exists($cfg->getOptions()->getConfigCacheFile())) { + @unlink($cfg->getOptions()->getConfigCacheFile()); + } } } }