Plugin Configuration

When your primary plugin class is constructed a couple of things happen behind the scenes

Path constant & method#

A constant is defined which defines the absolute path to your plugin directory, defined as YOURPLUGINNAME_PLUGIN_PATH. You can access this constant from anywhere, or you can use the path() method of your primary plugin class to get the path.

Example:

echo YOURPLUGINNAME_PLUGIN_PATH;

or

echo enact()->with('Plugin')->getPlugin('YourPluginName')->path();

or

echo \YourPluginName::instance()->path();

both of which will output /path/to/your-site/enact/plugin/yourpluginname

Configuration Files#

Configuration options stored in your plugin directory at app/config/config.php are loaded into the application configuration at an index that matches the name of your plugin.

Config File

<?php

return Array(
'foo' => 'bar',
'config' => 'value'
);

Access

$configs = enact()->config('YourPluginName');

Default configurations provided by your plugin will be merged with the users configuration for your plugin if it is defined. Users can extend the default configuration by defining a configuration file in the config folder at enact/config/YourPluginName.php.

Configuration via UI/UX#

You can also set up a page with a URI/slug defined by the method configUri() in your primary plugin class in which you provide a dedicated page for configuring settings/options for your plugin. If you return a string from the configUri() method users will be directed there after install, and your plugin name on the plugin management screen will always link to the page. It will be up to your to create the routes (make sure their private!) for handling the displaying of the page and performing the updates via a POST or PUT request.

If you use this method you can store your configuration options in a database table that you created specifically for configuration, or you can use the config setting table that is already defined by enact.

Example of using ConfigSetting:

set a value, you can also encode json and put it in there

enact()->with('ConfigSetting')->set('YourPluginName.setting', 'value');

get a value

$value = enact()->with('ConfigSetting')->setting('YourPluginName.setting');

See the full API specs for the ConfigSetting service.

Services & Factories#

If your plugin defines services in your plugin directory at app/config/services.php the services will automatically be registered into the application container when your primary plugin class is constructed. The same goes for factory services located at app/config/factories.php.

See the Disco PHP docs on service & factory configuration files and the application container.

Service configuration file

<?php

return Array(
'YourFooService' => '\YourPluginNamespace\service\Foo',
'YourBarService' => '\YourPluginNamespace\service\Bar',
);

Accessing your services

$fooService = enact()->with('YourFooService');

or

$barService = enact('YourBarService');