gulios/sxf-config

SXF Config Component

1.1.1 2018-09-06 10:26 UTC

This package is auto-updated.

Last update: 2024-11-07 00:22:50 UTC


README

The Config component based on Illuminate and DotEnv packages. (Laravel idea)

Features

  • store authorization values in .env
  • use cached configuration
  • default values for ENV
  • nested configuration structure
Example usage:
  1. Use Composer to install SXF Config into your project:

    composer require gulios/sxf-config
  2. Initialize in your code:

$basePath = realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR;

$configuration = new Config();
$configuration->setConfigFilesPath($basePath . 'config/');
$configuration->setEnvFile($basePath . '.env');
$configuration->setCacheConfigFile($basePath . 'cache/configuration.php');

You can get configuration by:

$configuration->getAll();

or

$configuration->get('app.debug')

etc

Configuration data

Package scan all .php files in defined path (setConfigFilesPath()).

Example file 'config/app.php'

return [
    'first_test' => env('TEST', 'defaultvalue'),
    'second_test' => [
        'key' => 'value'
    ]
];

As you see if you don't set TEST value in .env file it will get 'defaultvalue'.

Config directory structure can be nested.

Cache

You can execute just:

$configuration->clearCache();
or
$configuration->createCache();

or if you use Symfony console you can use two commands:

$config = new Config();
$config->setConfigFilesPath($basePath . 'config/');
$config->setEnvFile($basePath . '.env');
$config->setCacheConfigFile($basePath . 'cache/configuration.php');

$app = new Application();

$app->add(
    new ConfigCacheCommand(
        $config->getConfigFilesPath(),
        $config->getEnvFile(),
        $config->getCacheConfigFile()
    )
);
$app->add(
    new ConfigCacheClearCommand(
        $config->getConfigFilesPath(),
        $config->getEnvFile(),
        $config->getCacheConfigFile()
    )
);

$app->run();

and run:

php bin/console config:
  Command "config:" is ambiguous.
  Did you mean one of these?
      config:create Create a cache file for faster configuration loading
      config:clear  Remove the configuration cache file

it will create cache file with all your configuration.