Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/ublaboo/api-router
Browse files Browse the repository at this point in the history
  • Loading branch information
paveljanda committed Feb 22, 2016
2 parents 8fb4de5 + 1c7e0f3 commit a6bb4dc
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/DI/ApiRouterExtension.php
Expand Up @@ -18,15 +18,25 @@
class ApiRouterExtension extends Nette\DI\CompilerExtension
{

/**
* @var array
*/
private $defaults = [
'ignoreAnnotation' => []
];


/**
* @return void
*/
public function beforeCompile()
{
$config = $this->_getConfig();

$builder = $this->getContainerBuilder();
$config = $this->compiler->getConfig();
$compiler_config = $this->compiler->getConfig();

$routes = $this->findRoutes($builder, $config);
$routes = $this->findRoutes($builder, $compiler_config, $config);

$builder->addDefinition($this->prefix('resolver'))
->setClass('Ublaboo\ApiRouter\DI\ApiRoutesResolver')
Expand All @@ -41,7 +51,7 @@ public function beforeCompile()
* @param array $config
* @return array
*/
private function findRoutes(Nette\DI\ContainerBuilder $builder, $config)
private function findRoutes(Nette\DI\ContainerBuilder $builder, $compiler_config, $config)
{
/**
* Prepare AnnotationRegistry
Expand All @@ -50,14 +60,19 @@ private function findRoutes(Nette\DI\ContainerBuilder $builder, $config)
AnnotationRegistry::registerFile(__DIR__ . '/../ApiRouteSpec.php');

AnnotationReader::addGlobalIgnoredName('persistent');
AnnotationReader::addGlobalIgnoredName('inject');

foreach ($config['ignoreAnnotation'] as $ignore) {
AnnotationReader::addGlobalIgnoredName($ignore);
}

/**
* Prepare AnnotationReader - use cached values
*/
$reader = new FileCacheReader(
new AnnotationReader,
$config['parameters']['tempDir'] . '/cache/ApiRouter.Annotations',
$debug = $config['parameters']['debugMode']
$compiler_config['parameters']['tempDir'] . '/cache/ApiRouter.Annotations',
$debug = $compiler_config['parameters']['debugMode']
);

/**
Expand Down Expand Up @@ -151,4 +166,16 @@ private function findRoutes(Nette\DI\ContainerBuilder $builder, $config)
return $return;
}


private function _getConfig()
{
$config = $this->validateConfig($this->defaults, $this->config);

if (!is_array($config['ignoreAnnotation'])) {
$config['ignoreAnnotation'] = [$config['ignoreAnnotation']];
}

return $config;
}

}

0 comments on commit a6bb4dc

Please sign in to comment.