PHP Classes

File: Config/config.php

Recommend this page to a friend!
  Classes of Nerijus   CakePHP 2 Zend Service Manager integration   Config/config.php   Download  
File: Config/config.php
Role: Configuration script
Content type: text/plain
Description: Configuration script
Class: CakePHP 2 Zend Service Manager integration
Integrates the Zend Service Manager with CakePHP 2
Author: By
Last change:
Date: 6 years ago
Size: 1,383 bytes


Class file image Download

use Zend\Stdlib\ArrayUtils;

 * Configuration files are loaded in a specific order. First ``global.php``,
 * then ``*.global.php``. then ``local.php`` and finally ``*.local.php``. This
 * way local settings overwrite global settings. The configuration can be
 * cached. This can be done by setting ``config_cache_enabled`` to ``true``.
 * Obviously, if you use closures in your config you can't cache it.

$cachedConfigFile = Configure::read('zendservicemanager.cache-file') ?: CACHE . 'zend-service-manager-cache.php';

$config = [];
if (
is_file($cachedConfigFile)) {
// Try to load the cached config
$config = include $cachedConfigFile;
} else {
$configDir = Configure::read('zendservicemanager.autoload-dir') ?: APP . 'Config' . DS . 'Autoload' . DS;
// Load configuration from autoload path
foreach (Glob::glob($configDir . '{{,*.}global,{,*.}local}.php', Glob::GLOB_BRACE) as $file) {
$config = ArrayUtils::merge($config, include $file);
// Cache config if enabled
if (isset($config['config_cache_enabled']) && $config['config_cache_enabled'] === true) {
file_put_contents($cachedConfigFile, '<?php return ' . var_export($config, true) . ';');

// Return an ArrayObject so we can inject the config as a service
// and still use array checks like ``is_array``.
return new ArrayObject($config, ArrayObject::ARRAY_AS_PROPS);