1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Bridges\FormsDI;
9:
10: use Nette;
11:
12:
13: 14: 15:
16: class FormsExtension extends Nette\DI\CompilerExtension
17: {
18: public $defaults = array(
19: 'messages' => array(),
20: );
21:
22:
23: public function afterCompile(Nette\PhpGenerator\ClassType $class)
24: {
25: $initialize = $class->getMethod('initialize');
26: $config = $this->validateConfig($this->defaults);
27:
28: foreach ((array) $config['messages'] as $name => $text) {
29: if (defined('Nette\Forms\Form::' . $name)) {
30: $initialize->addBody('Nette\Forms\Validator::$messages[Nette\Forms\Form::?] = ?;', array($name, $text));
31: } elseif (defined($name)) {
32: $initialize->addBody('Nette\Forms\Validator::$messages[' . $name . '] = ?;', array($text));
33: } else {
34: throw new Nette\InvalidArgumentException('Constant Nette\Forms\Form::' . $name . ' or constant ' . $name . ' does not exist.');
35: }
36: }
37: }
38:
39: }
40: