gulios / sxf-config
SXF Config Component
1.1.1
2018-09-06 10:26 UTC
Requires
- php: ^7.1.3
- illuminate/config: 5.6.*
- nunomaduro/collision: 2.0.*
- symfony/console: 4.0.*
- symfony/filesystem: 4.0.*
- vlucas/phpdotenv: 2.5.*
Requires (Dev)
- filp/whoops: 2.1.*
- fzaninotto/faker: 1.7.*
- phpunit/phpunit: 7.0.*
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:
-
Use Composer to install SXF Config into your project:
composer require gulios/sxf-config
-
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.