1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Config\Extensions;
9:
10: use Nette;
11:
12:
13: 14: 15: 16: 17:
18: class PhpExtension extends Nette\Config\CompilerExtension
19: {
20:
21: public function afterCompile(Nette\Utils\PhpGenerator\ClassType $class)
22: {
23: $initialize = $class->methods['initialize'];
24: foreach ($this->getConfig() as $name => $value) {
25: if (!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(?);', array(str_replace(';', PATH_SEPARATOR, $value)));
30:
31: } elseif ($name === 'ignore_user_abort') {
32: $initialize->addBody('ignore_user_abort(?);', array($value));
33:
34: } elseif ($name === 'max_execution_time') {
35: $initialize->addBody('set_time_limit(?);', array($value));
36:
37: } elseif ($name === 'date.timezone') {
38: $initialize->addBody('date_default_timezone_set(?);', array($value));
39:
40: } elseif (function_exists('ini_set')) {
41: $initialize->addBody('ini_set(?, ?);', array($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: }
50: