1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\DI\Extensions;
9:
10: use Nette;
11:
12:
13: 14: 15:
16: class PhpExtension extends Nette\DI\CompilerExtension
17: {
18: public function afterCompile(Nette\PhpGenerator\ClassType $class)
19: {
20: $initialize = $class->getMethod('initialize');
21: foreach ($this->getConfig() as $name => $value) {
22: if ($value === null) {
23: continue;
24:
25: } elseif (!is_scalar($value)) {
26: throw new Nette\InvalidStateException("Configuration value for directive '$name' is not scalar.");
27:
28: } elseif ($name === 'include_path') {
29: $initialize->addBody('set_include_path(?);', [str_replace(';', PATH_SEPARATOR, $value)]);
30:
31: } elseif ($name === 'ignore_user_abort') {
32: $initialize->addBody('ignore_user_abort(?);', [$value]);
33:
34: } elseif ($name === 'max_execution_time') {
35: $initialize->addBody('set_time_limit(?);', [$value]);
36:
37: } elseif ($name === 'date.timezone') {
38: $initialize->addBody('date_default_timezone_set(?);', [$value]);
39:
40: } elseif (function_exists('ini_set')) {
41: $initialize->addBody('ini_set(?, ?);', [$name, $value]);
42:
43: } elseif (ini_get($name) != $value) {
44: throw new Nette\NotSupportedException('Required function ini_set() is disabled.');
45: }
46: }
47: }
48: }
49: