Skip to content
Permalink
Browse files

FormsExtension: uses configuration Schema

  • Loading branch information...
dg committed Mar 11, 2019
1 parent c30df77 commit 7ef0d56868ba106660df29f904a11f7d2be9ea31
Showing with 11 additions and 5 deletions.
  1. +3 −0 composer.json
  2. +8 −5 src/Bridges/FormsDI/FormsExtension.php
@@ -26,6 +26,9 @@
"latte/latte": "^2.4.1",
"tracy/tracy": "^2.4"
},
"conflict": {
"nette/di": "<3.0-stable"
},
"autoload": {
"classmap": ["src/"]
},
@@ -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)) {

0 comments on commit 7ef0d56

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