-
-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathFormsExtension.php
More file actions
43 lines (34 loc) · 1.05 KB
/
FormsExtension.php
File metadata and controls
43 lines (34 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Bridges\FormsDI;
use Nette;
/**
* Forms extension for Nette DI.
*/
class FormsExtension extends Nette\DI\CompilerExtension
{
public function __construct()
{
$this->config = new class {
/** @var string[] */
public array $messages = [];
};
}
public function afterCompile(Nette\PhpGenerator\ClassType $class)
{
$initialize = $this->initialization ?? $class->getMethod('initialize');
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)) {
$initialize->addBody('Nette\Forms\Validator::$messages[' . $name . '] = ?;', [$text]);
} else {
throw new Nette\InvalidArgumentException('Constant Nette\Forms\Form::' . $name . ' or constant ' . $name . ' does not exist.');
}
}
}
}