Application Config

Use application config API to modify and access application configuration.

Config Interface

Note

The configuration is read-only after application is fully bootstrapped.

$app->getConfig()

Accessing application configuration.

/** @var \Zend\Config\Config $config */
$config = $app->getConfig();

Note

It is possible to set configuration values before application is fully bootstrapped.

Setting configuration value.

$app->getConfig()->myConfigKey = 'myConfigValue';

Getting configuration value.

/** @var \Zend\Config\Config|mixed $myConfig */
$myConfig = $app->getConfig('myConfigKey', $default = null);

$app->getCoreConfig()

Getting core configuration value.

/** @var \Zend\Config\Config|mixed $myCoreConfig */
$myCoreConfig = $app->getCoreConfig('myCoreConfigKey', $default = null);

Config Features

Config features are registered into the configuration like following:

use WebinoAppLib\Feature\Config;

new Config([
    new SomeConfigFeature,
]);

Available features:

Events

Use event system config features to configure listeners.

Listener

Configuring listeners.

use WebinoAppLib\Feature\Config;
use WebinoAppLib\Feature\Listener;

new Config([
    // invokable
    new Listener(MyExampleListener::class),
    // factory
    new Listener(MyExampleListener::class, MyExampleListenerFactory::class),
]);

CoreListener

Configuring core listeners.

use WebinoAppLib\Application\CoreConfig;
use WebinoAppLib\Feature\CoreListener;

new CoreConfig([
    // invokable
    new CoreListener(MyExampleCoreListener::class),
    // factory
    new CoreListener(MyExampleCoreListener::class, MyExampleCoreListenerFactory::class),
]);

Services

Use services config features to configure invokable services and service factories.

Service

Configuring services.

use WebinoAppLib\Feature\Config;
use WebinoAppLib\Feature\Service;

new Config([
    // invokable
    new Service(MyService::class),
    // factory
    new Service(MyService::class, MyServiceFactory::class),
]);

CoreService

Application core service config feature.

use WebinoAppLib\Application\CoreConfig;
use WebinoAppLib\Feature\CoreService;

new CoreConfig([
    // invokable
    new CoreService(MyCoreService::class),
    // factory
    new CoreService(MyCoreService::class, MyCoreServiceFactory::class),
]);

Logging

Use logging config features to configure logging.

Log

Configuring app file logger writer, data/log/app.log by default.

use WebinoAppLib\Application\CoreConfig;
use WebinoConfigLib\Feature\Log;

new CoreConfig([
    // Enabling default logging
    new Log,
    // Overriding default logging file
    new Log('my/folder/app.log'),
]);

Configuring file logger formatting.

use WebinoAppLib\Application\CoreConfig;
use WebinoConfigLib\Feature\Log;

new CoreConfig([
    // Simple format
    (new Log)->setSimpleFormat('%timestamp% %priorityName% (%priority%): %message% %extra%'),

    // XML format
    (new Log('my/folder/app.log.xml'))->setXmlFormat(),
]);
Forking Logger

Creating new logger writer instead of overriding the default.

use WebinoAppLib\Application\CoreConfig;
use WebinoConfigLib\Feature\Log;

new CoreConfig([
    (new Log('my/folder/my-app.log'))->setName('my'),
]);

Logger

Configuring custom logger.

use WebinoAppLib\Feature\Config;
use WebinoConfigLib\Feature\Log;
use WebinoConfigLib\Feature\Logger;
use WebinoConfigLib\Feature\FirePhpLog;

new Config([
    new Logger('myLogger', [
        new Log,
        // etc.
    ]),
]);

ChromePhpLog

Configuring app ChromePHP logger writer.

use WebinoAppLib\Application\CoreConfig;
use WebinoConfigLib\Feature\ChromePhpLog;

new CoreConfig([
    new ChromePhpLog,
]);

FirePhpLog

Configuring app FirePHP logger writer.

use WebinoAppLib\Application\CoreConfig;
use WebinoConfigLib\Feature\FirePhpLog;

new CoreConfig([
    new FirePhpLog,
]);

Caching

Use cache config features to configure caching.

ConfigCacheEnabled

Toggling application config caching.

use WebinoAppLib\Feature\Config;
use WebinoConfigLib\Feature\ConfigCacheEnabled;

new Config([
    // enable
    new ConfigCacheEnabled,
    // disable
    new ConfigCacheEnabled(false),
]);

See also

Caching Methods

FilesystemCache

Configuring filesystem cache.

use WebinoAppLib\Application\CoreConfig;
use WebinoAppLib\Feature\FilesystemCache;

new CoreConfig([
    new FilesystemCache,
]);

MemoryCache

Configuring in memory cache.

use WebinoAppLib\Application\CoreConfig;
use WebinoAppLib\Feature\MemoryCache;

new CoreConfig([
    new MemoryCache,
]);

Filesystem

Use filesystem config features to configure filesystems.

DefaultFilesystem

Overriding default local working dir filesystem.

use WebinoAppLib\Application\CoreConfig;
use WebinoAppLib\Feature\DefaultFilesystem;

new CoreConfig([
    // optional
    new DefaultFilesystem('custom/root'),
]);

See also

$app->file()

MemoryFilesystem

Configuring temporary filesystem in the memory.

use WebinoAppLib\Application\CoreConfig;
use WebinoAppLib\Feature\MemoryFilesystem;

new CoreConfig([
    new MemoryFilesystem,
]);

Routing

Use routing config features to configure routing.

Route

Adding routes via config.

use WebinoAppLib\Feature\Config;
use WebinoConfigLib\Feature\Route;

new Config([
    (new Route('myRoute'))->setLiteral('/my/route/path'),
]);