Skip to content
Permalink
Browse files

TracyExtension: added getConfigSchema()

  • Loading branch information...
dg committed Mar 11, 2019
1 parent 92b97ca commit 85b73dc665082788829fc032b931c3093a0c8f67
Showing with 30 additions and 24 deletions.
  1. +4 −1 composer.json
  2. +26 −23 src/Bridges/Nette/TracyExtension.php
@@ -21,10 +21,13 @@
},
"require-dev": {
"nette/utils": "^2.4 || ^3.0",
"nette/di": "^2.4 || ~3.0.0",
"nette/di": "^3.0",
"nette/tester": "^2.2",
"psr/log": "^1.0"
},
"conflict": {
"nette/di": "<3.0"
},
"suggest": {
"https://nette.org/donate": "Please support Tracy via a donation"
},
@@ -10,6 +10,7 @@
namespace Tracy\Bridges\Nette;
use Nette;
use Nette\DI\Config\Expect;
use Tracy;
@@ -18,26 +19,6 @@
*/
class TracyExtension extends Nette\DI\CompilerExtension
{
public $defaults = [
'email' => null,
'fromEmail' => null,
'logSeverity' => null,
'editor' => null,
'browser' => null,
'errorTemplate' => null,
'strictMode' => null,
'showBar' => null,
'maxLen' => null,
'maxLength' => null,
'maxDepth' => null,
'showLocation' => null,
'scream' => null,
'bar' => [], // of class name
'blueScreen' => [], // of callback
'editorMapping' => [],
'netteMailer' => true,
];
/** @var bool */
private $debugMode;
@@ -52,9 +33,31 @@ public function __construct(bool $debugMode = false, bool $cliMode = false)
}
public function getConfigSchema(): Nette\DI\Config\Schema
{
return Expect::array([
'email' => Expect::email(),
'fromEmail' => Expect::email(),
'logSeverity' => Expect::scalar(),
'editor' => Expect::string(),
'browser' => Expect::string(),
'errorTemplate' => Expect::string(),
'strictMode' => Expect::bool(),
'showBar' => Expect::bool(),
'maxLength' => Expect::int(),
'maxDepth' => Expect::int(),
'showLocation' => Expect::bool(),
'scream' => Expect::bool(),
'bar' => Expect::listOf('class'),
'blueScreen' => Expect::listOf('callable'),
'editorMapping' => Expect::arrayOf('string'),
'netteMailer' => Expect::bool(true),
]);
}
public function loadConfiguration()
{
$this->validateConfig($this->defaults);
$builder = $this->getContainerBuilder();
$builder->addDefinition($this->prefix('logger'))
@@ -104,7 +107,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
}
if ($this->debugMode) {
foreach ((array) $this->config['bar'] as $item) {
foreach ($this->config['bar'] as $item) {
if (is_string($item) && substr($item, 0, 1) === '@') {
$item = new Nette\DI\Statement(['@' . $builder::THIS_CONTAINER, 'getService'], [substr($item, 1)]);
} elseif (is_string($item)) {
@@ -122,7 +125,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
}
}
foreach ((array) $this->config['blueScreen'] as $item) {
foreach ($this->config['blueScreen'] as $item) {
$initialize->addBody($builder->formatPhp(
'$this->getService(?)->addPanel(?);',
Nette\DI\Helpers::filterArguments([$this->prefix('blueScreen'), $item])

0 comments on commit 85b73dc

Please sign in to comment.
You can’t perform that action at this time.