-
Notifications
You must be signed in to change notification settings - Fork 28
Config
- General
- Laravel
- Method Index
- Access Config
- Get Config Values
- Change Config Values at Runtime
- MeCab Interface Bindings
The config class, Config.php, is a singleton that stores a copy of the config file, config.php, on the object. Any runtime altercations to config values occur to only the object copy, not to the master config.php array. This allows for easy config changes at runtime, but also gives the client the ability to restore the original values by simply getting a fresh copy of config.php. Keep in mind that because the class is a singleton, any config changes will be made global.
If you are using Laravel, publish the config file to the main app config folder using the command line artisan publish command.
php artisan vendor:publish
Your config file will be copied to config/limelight.php.
To access config, simply get the instance of the class with the getInstance() method..
To access the config class, use the static getInstance() method.
use Limelight\Config\Config;
//
$config = Config::getInstance();
The returned class will be the singleton Limelight\Config\Config.
Use the get() method to get config values from the config file. get() takes one argument, the config value key and returns the keys value.
$config->get('bindings');
Return Value: ['Limelight\Mecab\Mecab' => 'Limelight\Mecab\PhpMecab\PhpMecab']
Use the getPlugins() method to get an array containing all registered plugins. The method takes no arguments.
$config->getPlugins();
Return Value:
[
'Furigana' => 'Limelight\Plugins\Library\Furigana\Furigana',
'Romaji' => 'Limelight\Plugins\Library\Romaji\Romaji'
]
At runtime, it is possible to change config values, delete them entirely, or restore them to the values defined in config.php.
Set config values at runtime. set() takes three arguments, $value, $key1, and $key2. $value is the value to be set, $key1 is the first level of the multidimensional config array, and $key2 is the second level.
The example code will use the config settings for the Romaji plugin.
'Romaji' => [
'style' => 'hepburn_modified'
]
To change the style from 'hepburn_modified' to 'hepburn_traditional':
$config->set('hepburn_traditional', 'Romaji', 'style');
Reset config values to those found in config.php.
$config->resetConfig();
Unset a config entry. erase() takes two methods, $key1 and $key2 representing layer 1 and layer 2 in the multidimensional config array. This method mostly exists for testing purposes and could cause runtime breakages.
$config->erase('Romaji', 'style');
By default, the interface Limelight\Mecab\Mecab is bound to the class Limelight\Mecab\PhpMecab\PhpMecab, a wrapper for the php-mecab bindings. This means that at boot time, when Limelight asks for the interface Mecab, the Phpmecab implementation of the interface is resolved. Theoretically, this should make it fairly easy to switch out php-mecab for bindings of your choice, although this has not been tested. To do it, make a class that implements Limelight\Mecab\Mecab and another for nodes that implements Limelight\Mecab\Node. Then, change the bindings value in config.php to your implementations namespace.