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:
19: public function afterCompile(Nette\PhpGenerator\ClassType $class)
20: {
21: $initialize = $class->getMethod('initialize');
22: foreach ($this->getConfig() as $name => $value) {
23: if ($value === NULL) {
24: continue;
25:
26: } elseif (!is_scalar($value)) {
27: throw new Nette\InvalidStateException("Configuration value for directive '$name' is not scalar.");
28:
29: } elseif ($name === 'include_path') {
30: $initialize->addBody('set_include_path(?);', array(str_replace(';', PATH_SEPARATOR, $value)));
31:
32: } elseif ($name === 'ignore_user_abort') {
33: $initialize->addBody('ignore_user_abort(?);', array($value));
34:
35: } elseif ($name === 'max_execution_time') {
36: $initialize->addBody('set_time_limit(?);', array($value));
37:
38: } elseif ($name === 'date.timezone') {
39: $initialize->addBody('date_default_timezone_set(?);', array($value));
40:
41: } elseif (function_exists('ini_set')) {
42: $initialize->addBody('ini_set(?, ?);', array($name, $value));
43:
44: } elseif (ini_get($name) != $value) {
45: throw new Nette\NotSupportedException('Required function ini_set() is disabled.');
46: }
47: }
48: }
49:
50: }
51: