Skip to content

Commit 33b188d

Browse files
committed
Compiler: triggers schema warnings
1 parent e9c866e commit 33b188d

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/DI/Compiler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,14 @@ private function processSchema(Schema\Schema $schema, array $configs, $name = nu
276276
$context->dynamics = &$this->extensions[self::PARAMETERS]->dynamicValidators;
277277
};
278278
try {
279-
return $processor->processMultiple($schema, $configs);
279+
$res = $processor->processMultiple($schema, $configs);
280280
} catch (Schema\ValidationException $e) {
281281
throw new Nette\DI\InvalidConfigurationException($e->getMessage());
282282
}
283+
foreach ($processor->getWarnings() as $warning) {
284+
trigger_error($warning, E_USER_DEPRECATED);
285+
}
286+
return $res;
283287
}
284288

285289

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\DI\CompilerExtension and schema validation
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Nette\Schema\Expect;
10+
use Tester\Assert;
11+
12+
13+
require __DIR__ . '/../bootstrap.php';
14+
15+
16+
class FooExtension extends Nette\DI\CompilerExtension
17+
{
18+
public $loadedConfig;
19+
20+
21+
public function getConfigSchema(): Nette\Schema\Schema
22+
{
23+
return Expect::structure([
24+
'key' => Expect::string()->deprecated(),
25+
]);
26+
}
27+
28+
29+
public function loadConfiguration()
30+
{
31+
$this->loadedConfig = $this->config;
32+
}
33+
}
34+
35+
36+
Assert::error(function () {
37+
$compiler = new Nette\DI\Compiler;
38+
$compiler->addExtension('foo', $foo = new FooExtension);
39+
createContainer($compiler, '
40+
foo:
41+
key: hello
42+
');
43+
}, E_USER_DEPRECATED, "The item 'foo › key' is deprecated.");

0 commit comments

Comments
 (0)