Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	bundle/Spec/CirclicalAutoWire/Service/RouterServiceSpec.php
  • Loading branch information
Saeven committed Aug 10, 2017
2 parents 7c189e4 + 4798240 commit 3687bc1
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
// ...
Expand Down
21 changes: 21 additions & 0 deletions bundle/Spec/CirclicalAutoWire/Annotations/OtherAnnotation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Spec\CirclicalAutoWire\Annotations;

/**
* Class OtherAnnotation
*
* @package Spec\CirclicalAutoWire\Annotations
* @author Michał Makaruk <[email protected]>
*
* @Annotation
* @Target({"METHOD","CLASS"})
*/
final class OtherAnnotation
{
/**
* @var string
*/
public $value;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Spec\CirclicalAutoWire\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use CirclicalAutoWire\Annotations\Route;
use Spec\CirclicalAutoWire\Annotations\OtherAnnotation;

/**
* Class OtherAnnotationsTypeErrorController
* @package Spec\CirclicalAutoWire\Controller
*
* @Route("/foobar")
*/
class OtherAnnotationsController extends AbstractActionController
{
/**
* @Route("/")
*/
public function fooAction()
{
}

/**
* @OtherAnnotation
* @Route("/ok")
*/
public function willItFailAction()
{
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Spec\CirclicalAutoWire\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use CirclicalAutoWire\Annotations\Route;
use Spec\CirclicalAutoWire\Annotations\OtherAnnotation;

/**
* Class OtherAnnotationsTypeErrorController
* @package Spec\CirclicalAutoWire\Controller
*
*/
class OtherAnnotationsTypeErrorController extends AbstractActionController
{
/**
* @OtherAnnotation
* @Route("/will-it-fail")
*/
public function willItFailAction()
{
}

}
23 changes: 22 additions & 1 deletion bundle/Spec/CirclicalAutoWire/Service/RouterServiceSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace Spec\CirclicalAutoWire\Service;

use Doctrine\Common\Annotations\AnnotationRegistry;
use Spec\CirclicalAutoWire\Controller\AnnotatedController;
use Spec\CirclicalAutoWire\Controller\ChildRouteController;
use Spec\CirclicalAutoWire\Controller\DistantChildRouteController;
use Spec\CirclicalAutoWire\Controller\OtherAnnotationsController;
use Spec\CirclicalAutoWire\Controller\OtherAnnotationsTypeErrorController;
use Spec\CirclicalAutoWire\Controller\SameNameAController;
use Spec\CirclicalAutoWire\Controller\SameNameBController;
use Spec\CirclicalAutoWire\Controller\SimpleController;
Expand Down Expand Up @@ -214,6 +217,24 @@ function it_lets_children_have_same_names($routeStack)
$this->compile();
}

function it_skips_other_annotations()
{
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()
{
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]);
}

function its_annotions_can_be_reset()
{
$this->parseController(SameNameAController::class);
Expand All @@ -222,4 +243,4 @@ function its_annotions_can_be_reset()
$this->getAnnotations()->shouldBeArray();
$this->getAnnotations()->shouldHaveCount(0);
}
}
}
10 changes: 8 additions & 2 deletions src/CirclicalAutoWire/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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();

Expand All @@ -87,6 +87,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());
}
}
}
}
}

0 comments on commit 3687bc1

Please sign in to comment.