From 558e60a618484596f6e20843f60e7cad7d651796 Mon Sep 17 00:00:00 2001 From: Michal Haltuf Date: Fri, 12 Jul 2019 21:03:21 +0200 Subject: [PATCH 1/2] rewrite to ConfigSchema + fix incompatibilities with Kdyby\Doctrine for nette-3.0 --- src/DI/AnnotationsExtension.php | 38 ++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/DI/AnnotationsExtension.php b/src/DI/AnnotationsExtension.php index b79992c..7ce9e4f 100644 --- a/src/DI/AnnotationsExtension.php +++ b/src/DI/AnnotationsExtension.php @@ -20,25 +20,39 @@ use Nette\DI\Config\Helpers as ConfigHelpers; use Nette\PhpGenerator\ClassType as ClassTypeGenerator; use Nette\PhpGenerator\PhpLiteral; +use Nette\Schema\Expect; +use Nette\Schema\Schema; use Nette\Utils\Validators; class AnnotationsExtension extends \Nette\DI\CompilerExtension { - /** @var array */ - public $defaults = [ - 'ignore' => [ - 'persistent', - 'serializationVersion', - ], - 'cache' => 'default', - 'debug' => '%debugMode%', - ]; + /** @var bool */ + private $debugMode; + + public function __construct(bool $debugMode = FALSE) + { + $this->debugMode = $debugMode; + } + + public function getConfigSchema(): Schema + { + return Expect::structure([ + 'ignore' => Expect::arrayOf('string')->default([ + 'persistent', + 'serializationVersion', + ]), + 'cache' => Expect::string('default'), + 'debug' => Expect::bool(interface_exists('Tracy\IBarPanel')), + 'debugMode' => Expect::bool(interface_exists('Tracy\IBarPanel')), + ])->castTo('array'); + } public function loadConfiguration(): void { $builder = $this->getContainerBuilder(); - $config = $this->getConfig($this->defaults); + /** @var array $config */ + $config = $this->config; $reflectionReader = $builder->addDefinition($this->prefix('reflectionReader')) ->setType(AnnotationReader::class) @@ -54,8 +68,8 @@ public function loadConfiguration(): void ->setClass(Reader::class) ->setFactory(CachedReader::class, [ $this->prefix('@reflectionReader'), - Helpers::processCache($this, $config['cache'], 'annotations', $config['debug']), - $config['debug'], + Helpers::processCache($this, $config['cache'], 'annotations', $config['debug'] && $this->debugMode), + $config['debug'] && $this->debugMode, ]); // for runtime From f3d16cddf79bbca9253c839df375a70edab28f81 Mon Sep 17 00:00:00 2001 From: Michal Haltuf Date: Thu, 22 Aug 2019 09:54:10 +0200 Subject: [PATCH 2/2] We do not need global debugMode --- src/DI/AnnotationsExtension.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/DI/AnnotationsExtension.php b/src/DI/AnnotationsExtension.php index 7ce9e4f..f0ac5b9 100644 --- a/src/DI/AnnotationsExtension.php +++ b/src/DI/AnnotationsExtension.php @@ -27,14 +27,6 @@ class AnnotationsExtension extends \Nette\DI\CompilerExtension { - /** @var bool */ - private $debugMode; - - public function __construct(bool $debugMode = FALSE) - { - $this->debugMode = $debugMode; - } - public function getConfigSchema(): Schema { return Expect::structure([ @@ -68,8 +60,8 @@ public function loadConfiguration(): void ->setClass(Reader::class) ->setFactory(CachedReader::class, [ $this->prefix('@reflectionReader'), - Helpers::processCache($this, $config['cache'], 'annotations', $config['debug'] && $this->debugMode), - $config['debug'] && $this->debugMode, + Helpers::processCache($this, $config['cache'], 'annotations', $config['debug']), + $config['debug'], ]); // for runtime