Configuration - personaclix/PersonaClixEngine GitHub Wiki
You can configure many parts of the engine using a configuration file. The file must be in JSON format.
Step 1
Create a file anywhere in your installation (probably somewhere in the private folder would be best to prevent public access) and ensure it has the .json
extension.
Step 2
Add a use statement for the configuration class inside the public index.php
file.
use PersonaClix\Engine\Configuration;
If you want to shorten the name down or even change it from the current Configuration
, you can use as
.
use PersonaClix\Engine\Configuration as Config;
Then create a variable with a new instance of the class. You must call the constructor and pass in a string value with the path to where you placed the JSON file.
$config = new Config("../private/config.json");
Note that I am using the shorter class name of Config
here, but please make sure you use the one you specified in the use statement above if you used as
or simply Configuration
if you didn't.
Accessing Configuration Values
Use the member function get()
and pass in the name of the key you wish to retrieve from the JSON file as a String
.
$config->get('SomeKey');
The value of the key will be returned so it can be validated if needed before displaying.
Errors
Should the engine run into issues with the configuration, an error message will be returned instead of the value associated with the requested key. You can use PHP's error_log()
function to log it to the console or log file for further investigation.
error_log( $config->get('SomeKey') );
Or if you're the lazy type and can't be bothered looking amongst the massive error log file for one line, echo is also an option.
echo $config->get('SomeKey');