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