init
core configuration file performs a major role in the
way and manner in which the framework responds. In most cases, this file may not be visited often, however,
it is a useful feature to be able to configure the project application from the terminal which can save time and make
it easier to relate with the project application. The icore/init
file is designed to
anchor both core and custom configuration keys. This means that aside from the default configuration keys, we can set up several
other custom unique keys with their respective values which can later be fetched back through the Init
controller class.
Init
file is the initConfig
command. The sample syntax below explains how
parameters or keys can be defined for the init
file.
php mi initConfig KEY VALUE
initConfig
command is first defined after which a custom key and value are defined in the specified order.
With the sample command above, the init
file resembles the format below:
KEY: VALUE
php mi initConfig KEY -
Init
class was added to help manage the init
file. This helps to retrieve
values of keys stored in the init
file. The class below will retrieve the Init file configuration
keys.
<?php use \spoova\mi\core\classes\Init class SomeClass { function __construct() { // Fetch a key's value from init file $mykey = Init::key('KEY'); // Fetch all keys and their value from init file $allKeys = Init::values(); // Fetch specified keys and their value from init file $onlyKeys = Init::values(['KEY1','KEY2']); } }
Init::key()
method. This is shown below:
<?php
use \spoova\mi\core\classes\Init
class SomeClass {
function __construct() {
// Fetch a key or use alternate value
$mykey = Init::key('KEY', 'alternate_value');
}
}
Init::set()
method. This is because, values stored at runtime will be updated when this method is employed. This is
shown below:
<?php
use \spoova\mi\core\classes\Init
class SomeClass {
function __construct() {
if(Init::set('KEY','SOME_VALUE')) {
// key set successfully
}
}
}
Init::unset()
method. This method
can easily remove a single or multiple set of keys. Example is shown below:
<?php
use \spoova\mi\core\classes\Init
class SomeClass {
function __construct() {
$removeKeys = ['KEY1','KEY2'];
$removedKeys = Init::unset(['KEY1','KEY2');
if($removeKeys === $removedKeys) {
// all keys unset successfully
}
}
}
init
file was designed for custom configurations using the extended functionality of the
Filemanger
class. While it may be easier to manage the icore/init
file though Init
class,
it is suggested to use this class only when there is a necessity to do so. Developers should bear in mind that other core configuration parameters are
stored within the init
file.