Skip to content

Commit

Permalink
PhpExtension: simplification, uses only ini_set
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 13, 2023
1 parent 70f9e96 commit 7fde23c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
22 changes: 4 additions & 18 deletions src/Bootstrap/Extensions/PhpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,12 @@ public function getConfigSchema(): Nette\Schema\Schema
public function loadConfiguration()
{
foreach ($this->getConfig() as $name => $value) {
if ($value === null) {
continue;

} elseif ($name === 'include_path') {
$this->initialization->addBody('set_include_path(?);', [str_replace(';', PATH_SEPARATOR, $value)]);

} elseif ($name === 'ignore_user_abort') {
$this->initialization->addBody('ignore_user_abort(?);', [$value]);

} elseif ($name === 'max_execution_time') {
$this->initialization->addBody('set_time_limit(?);', [$value]);

} elseif ($name === 'date.timezone') {
$this->initialization->addBody('date_default_timezone_set(?);', [$value]);
if (!function_exists('ini_set')) {
throw new Nette\NotSupportedException('Required function ini_set() is disabled.');
}

} elseif (function_exists('ini_set')) {
if ($value !== null) {
$this->initialization->addBody('ini_set(?, (string) (?));', [$name, $value]);

} elseif (ini_get($name) !== (string) $value) {
throw new Nette\NotSupportedException('Required function ini_set() is disabled.');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Bootstrap/Configurator.basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Assert::same('%foo%', $container->parameters['foo2']);
Assert::same('%foo%', $container->parameters['foo3']);
Assert::same('hello', $container->parameters['bar']);
Assert::same('hello world', constant('BAR'));
Assert::same('Europe/Prague', date_default_timezone_get());
Assert::same('Europe/Prague', ini_get('date.timezone'));

Assert::same([
'dsn' => 'sqlite2::memory:',
Expand Down

0 comments on commit 7fde23c

Please sign in to comment.