Skip to content
Zach Leigh edited this page Apr 7, 2016 · 2 revisions

Contents

General

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.

Laravel

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.

Method Index

Access Config

To access config, simply get the instance of the class with the getInstance() method..


getInstance()

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.

Get Config Values


get()

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']


getPlugins()

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'
]

Change Config Values at Runtime

At runtime, it is possible to change config values, delete them entirely, or restore them to the values defined in config.php.


set()

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');

resetConfig()

Reset config values to those found in config.php.

$config->resetConfig();

erase()

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');

MeCab Interface Bindings

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.