When a Zend Framework application starts, the Zend_Application class is responsible for turning the keys found in application.ini (or any other confgiuration source) in to runtime behavior. The work is done in setOptions(), which is invoked automatically during bootstrap. Below are the most frequently used directives and the helper methods that actually apply them.
Directive → Method Map
// excerpt from Zend_Application::setOptions()
if (!empty($cfg['phpsettings'])) {
$this->applyPhpConfig($cfg['phpsettings']);
}
if (!empty($cfg['includepaths'])) {
$this->extendIncludePath($cfg['includepaths']);
}
if (!empty($cfg['autoloadernamespaces'])) {
$this->registerPrefixes($cfg['autoloadernamespaces']);
}
if (!empty($cfg['autoloaderzfpath'])) {
$loader = $this->getAutoloader();
if (method_exists($loader, 'setZfPath')) {
$zfPath = $cfg['autoloaderzfpath'];
$zfVersion = $cfg['autoloaderzfversion'] ?? 'latest';
$loader->setZfPath($zfPath, $zfVersion);
}
}
if (!empty($cfg['bootstrap'])) {
$bootstrap = $cfg['bootstrap'];
if (is_string($bootstrap)) {
$this->setBootstrap($bootstrap);
} elseif (is_array($bootstrap)) {
if (empty($bootstrap['path'])) {
throw new Zend_Application_Exception('Bootstrap path missing');
}
$this->setBootstrap($bootstrap['path'], $bootstrap['class'] ?? null);
} else {
throw new Zend_Application_Exception('Malformed bootstrap data');
}
}
Applying php.ini Settings
protected function applyPhpConfig(array $settings, string $prefix = ''): self
{
foreach ($settings as $key => $value) {
$fullKey = $prefix === '' ? $key : $prefix . $key;
if (is_scalar($value)) {
ini_set($fullKey, (string) $value);
} elseif (is_array($value)) {
$this->applyPhpConfig($value, $fullKey . '.');
}
}
return $this;
}
Example in application.ini:
phpSettings.display_errors = 1
phpSettings.date.timezone = "Europe/Berlin"
Extending the Include Path
protected function extendIncludePath(array $dirs): self
{
$new = implode(PATH_SEPARATOR, $dirs);
set_include_path($new . PATH_SEPARATOR . get_include_path());
return $this;
}
Example:
includepaths[] = APPLICATION_PATH "/../library/FooBar"
Quick check:
var_dump(get_include_path());
Registering Additional Autoloader Prefixes
protected function registerPrefixes(array $prefixes): self
{
$loader = $this->getAutoloader();
foreach ($prefixes as $ns) {
$loader->registerNamespace($ns);
}
return $this;
}
Example:
autoloadernamespaces[] = "FooBar_"