Skip to content

Commit

Permalink
FormsExtension: uses configuration Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 9, 2019
1 parent c30df77 commit 7ef0d56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions composer.json
Expand Up @@ -26,6 +26,9 @@
"latte/latte": "^2.4.1",
"tracy/tracy": "^2.4"
},
"conflict": {
"nette/di": "<3.0-stable"
},
"autoload": {
"classmap": ["src/"]
},
Expand Down
13 changes: 8 additions & 5 deletions src/Bridges/FormsDI/FormsExtension.php
Expand Up @@ -17,17 +17,20 @@
*/
class FormsExtension extends Nette\DI\CompilerExtension
{
private $defaults = [
'messages' => [],
];
public function __construct()
{
$this->config = new class {
/** @var string[] */
public $messages = [];
};
}


public function afterCompile(Nette\PhpGenerator\ClassType $class)
{
$initialize = $class->getMethod('initialize');
$config = $this->validateConfig($this->defaults);

foreach ((array) $config['messages'] as $name => $text) {
foreach ($this->config->messages as $name => $text) {
if (defined('Nette\Forms\Form::' . $name)) {
$initialize->addBody('Nette\Forms\Validator::$messages[Nette\Forms\Form::?] = ?;', [$name, $text]);
} elseif (defined($name)) {
Expand Down

0 comments on commit 7ef0d56

Please sign in to comment.