|
12 | 12 |
|
13 | 13 | namespace HttpAuthExtension; |
14 | 14 |
|
15 | | -use Nette; |
| 15 | +use Nette\Configurator; |
| 16 | +use Nette\DI\CompilerExtension; |
| 17 | +use Nette\PhpGenerator\ClassType; |
16 | 18 |
|
17 | 19 |
|
18 | | -class HttpAuthExtension extends Nette\DI\CompilerExtension |
| 20 | +class HttpAuthExtension extends CompilerExtension |
19 | 21 | { |
20 | 22 |
|
21 | | - /** @var array */ |
22 | | - public $defaults = array( |
23 | | - 'title' => 'Frontend authentication', |
24 | | - ); |
| 23 | + public function __construct() |
| 24 | + { |
| 25 | + $this->config = new class { |
| 26 | + /** @var string */ |
| 27 | + public $title = 'Frontend authentication'; |
| 28 | + |
| 29 | + /** @var string|null */ |
| 30 | + public $username; |
| 31 | + |
| 32 | + /** @var string|null */ |
| 33 | + public $password; |
| 34 | + }; |
| 35 | + } |
25 | 36 |
|
26 | 37 |
|
27 | | - public function afterCompile(Nette\PhpGenerator\ClassType $class): void |
| 38 | + public function afterCompile(ClassType $class): void |
28 | 39 | { |
29 | | - $config = $this->getConfig($this->defaults); |
| 40 | + $config = $this->config; |
30 | 41 |
|
31 | | - if (isset($config['username'], $config['password'])) { |
| 42 | + if (isset($config->username, $config->password, $config->title)) { |
32 | 43 | $initialize = $class->methods['initialize']; |
33 | 44 |
|
34 | 45 | $initialize->addBody('$auth = new HttpAuthExtension\HttpAuthenticator( $this->getByType(\'Nette\Http\IResponse\'), ?, ?, ? );', |
35 | | - array($config['username'], $config['password'], $config['title'])); |
| 46 | + [$config->username, $config->password, $config->title]); |
36 | 47 |
|
37 | 48 | $initialize->addBody('$auth->run();'); |
38 | 49 | } |
39 | 50 | } |
40 | 51 |
|
41 | 52 |
|
42 | | - public static function register(Nette\Configurator $configurator, string $prefix = 'httpAuth'): void |
| 53 | + public static function register(Configurator $configurator, string $prefix = 'httpAuth'): void |
43 | 54 | { |
44 | 55 | $class = __CLASS__; |
45 | 56 | $configurator->onCompile[] = static function ($configurator, $compiler) use ($prefix, $class): void { |
|
0 commit comments