Skip to content

Commit 3687bc1

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # bundle/Spec/CirclicalAutoWire/Service/RouterServiceSpec.php
2 parents 7c189e4 + 4798240 commit 3687bc1

File tree

6 files changed

+108
-4
lines changed

6 files changed

+108
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ On any action in a controller with the use statement, use these types of annotat
7373
7474
/**
7575
* Route with parameter, name, constraint, and defaults
76-
* @Route("/freedom/:param", name="easy-as-pie" constraints={"param":"[a-zA-Z]"}, defaults={"param":"index"})
76+
* @Route("/freedom/:param", name="easy-as-pie", constraints={"param":"[a-zA-Z]"}, defaults={"param":"index"})
7777
*/
7878
public function anyOldNameAction(){
7979
// ...
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Spec\CirclicalAutoWire\Annotations;
4+
5+
/**
6+
* Class OtherAnnotation
7+
*
8+
* @package Spec\CirclicalAutoWire\Annotations
9+
* @author Michał Makaruk <buliq1847@gmail.com>
10+
*
11+
* @Annotation
12+
* @Target({"METHOD","CLASS"})
13+
*/
14+
final class OtherAnnotation
15+
{
16+
/**
17+
* @var string
18+
*/
19+
public $value;
20+
21+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Spec\CirclicalAutoWire\Controller;
4+
5+
use Zend\Mvc\Controller\AbstractActionController;
6+
use CirclicalAutoWire\Annotations\Route;
7+
use Spec\CirclicalAutoWire\Annotations\OtherAnnotation;
8+
9+
/**
10+
* Class OtherAnnotationsTypeErrorController
11+
* @package Spec\CirclicalAutoWire\Controller
12+
*
13+
* @Route("/foobar")
14+
*/
15+
class OtherAnnotationsController extends AbstractActionController
16+
{
17+
/**
18+
* @Route("/")
19+
*/
20+
public function fooAction()
21+
{
22+
}
23+
24+
/**
25+
* @OtherAnnotation
26+
* @Route("/ok")
27+
*/
28+
public function willItFailAction()
29+
{
30+
}
31+
32+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Spec\CirclicalAutoWire\Controller;
4+
5+
use Zend\Mvc\Controller\AbstractActionController;
6+
use CirclicalAutoWire\Annotations\Route;
7+
use Spec\CirclicalAutoWire\Annotations\OtherAnnotation;
8+
9+
/**
10+
* Class OtherAnnotationsTypeErrorController
11+
* @package Spec\CirclicalAutoWire\Controller
12+
*
13+
*/
14+
class OtherAnnotationsTypeErrorController extends AbstractActionController
15+
{
16+
/**
17+
* @OtherAnnotation
18+
* @Route("/will-it-fail")
19+
*/
20+
public function willItFailAction()
21+
{
22+
}
23+
24+
}

bundle/Spec/CirclicalAutoWire/Service/RouterServiceSpec.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace Spec\CirclicalAutoWire\Service;
44

5+
use Doctrine\Common\Annotations\AnnotationRegistry;
56
use Spec\CirclicalAutoWire\Controller\AnnotatedController;
67
use Spec\CirclicalAutoWire\Controller\ChildRouteController;
78
use Spec\CirclicalAutoWire\Controller\DistantChildRouteController;
9+
use Spec\CirclicalAutoWire\Controller\OtherAnnotationsController;
10+
use Spec\CirclicalAutoWire\Controller\OtherAnnotationsTypeErrorController;
811
use Spec\CirclicalAutoWire\Controller\SameNameAController;
912
use Spec\CirclicalAutoWire\Controller\SameNameBController;
1013
use Spec\CirclicalAutoWire\Controller\SimpleController;
@@ -214,6 +217,24 @@ function it_lets_children_have_same_names($routeStack)
214217
$this->compile();
215218
}
216219

220+
function it_skips_other_annotations()
221+
{
222+
include __DIR__ . '/../../CirclicalAutoWire/Controller/OtherAnnotationsController.php';
223+
AnnotationRegistry::registerAutoloadNamespace("Spec\\CirclicalAutoWire\\Annotations", realpath(__DIR__ . "/../../../"));
224+
225+
$this->shouldNotThrow(\Error::class)->during('parseController', [OtherAnnotationsController::class]);
226+
}
227+
228+
function it_skips_other_annotations_type_error()
229+
{
230+
include __DIR__ . '/../../CirclicalAutoWire/Controller/OtherAnnotationsTypeErrorController.php';
231+
AnnotationRegistry::registerAutoloadNamespace("Spec\\CirclicalAutoWire\\Annotations", realpath(__DIR__ . "/../../../"));
232+
233+
//this should be thrown, but I'm unable to force it...
234+
// $this->shouldThrow(\TypeError::class)->during('parseController', [OtherAnnotationsTypeErrorController::class]);
235+
$this->shouldNotThrow(\PhpSpec\Exception\Example\ErrorException::class)->during('parseController', [OtherAnnotationsTypeErrorController::class]);
236+
}
237+
217238
function its_annotions_can_be_reset()
218239
{
219240
$this->parseController(SameNameAController::class);
@@ -222,4 +243,4 @@ function its_annotions_can_be_reset()
222243
$this->getAnnotations()->shouldBeArray();
223244
$this->getAnnotations()->shouldHaveCount(0);
224245
}
225-
}
246+
}

src/CirclicalAutoWire/Module.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function onBootstrap(MvcEvent $mvcEvent)
6363
$config = $serviceLocator->get('config');
6464
$productionMode = Console::isConsole() || $config['circlical']['autowire']['production_mode'];
6565

66-
if (!$productionMode) {
66+
if (!$productionMode || !file_exists($config['circlical']['autowire']['compile_to'])) {
6767
$routerService = $serviceLocator->get(RouterService::class);
6868
$directoryScanner = new DirectoryScanner();
6969

@@ -87,6 +87,12 @@ public function onBootstrap(MvcEvent $mvcEvent)
8787
$writer = new PhpArray();
8888
$writer->toFile($config['circlical']['autowire']['compile_to'], $routeConfig, true);
8989
$routerService->reset();
90+
91+
/** @var \Zend\ModuleManager\Listener\ConfigListener $cfg */
92+
$cfg = $serviceLocator->get(\Zend\ModuleManager\ModuleManager::class)->getEvent()->getConfigListener();
93+
if ($productionMode && $cfg->getOptions()->getConfigCacheEnabled() && file_exists($cfg->getOptions()->getConfigCacheFile())) {
94+
@unlink($cfg->getOptions()->getConfigCacheFile());
95+
}
9096
}
9197
}
92-
}
98+
}

0 commit comments

Comments
 (0)