The Configuration object
From the AbstractConfiguration class
For advanced usage, it is recommended to create a Configuration
class extending AbstractConfiguration
.
You can there tweak the providers, middlewares, etc. in a more advanced fashion:
class MyConfiguration extends \Madewithlove\Glue\AbstractConfiguration
{
public function __construct()
{
$this->providers = [new SomeServiceProvider()];
$this->someCustomConfig = 'foobar';
}
}
If you need access to the container or environment variables, you can do so through the configure
method which is called
on the configuration once these two are booted:
class MyConfiguration extends \Madewithlove\Glue\AbstractConfiguration
{
public function __construct()
{
$this->providers = [new SomeServiceProvider()];
$this->someCustomConfig = 'foobar';
}
public function configure()
{
$this->debug = $this->container->get('something') ?: getenv('FOOBAR');
}
}
If arrays are more your thing, you can just call the parent constructor with the array:
class MyConfiguration extends \Madewithlove\Glue\AbstractConfiguration
{
public function __construct()
{
parent::__construct([
'providers' => [new SomeServiceProvider()],
'someCustomConfig' => 'foobar',
]);
}
}
Once you have your class, simply pass it to the application constructor:
$app = new Glue(new MyConfiguration());
$app->run();
You can change the configuration at any time through the getter and setter:
$configuration = $app->getConfiguration();
$configuration->setPaths($paths);
$app->setConfiguration($configuration);
Going commando
If you don't like the base configuration class you can just create a custom class and make it implement ConfigurationInterface
:
class MyConfiguration implements ConfigurationInterface
{
public function isDebug()
{
return true;
}
public function getRootPath()
{
return 'some/path';
}
public function getPaths()
{
return [
'cache' => 'storage/cache',
];
}
// etc.
}
Boot event
The configurations can facultatively have a boot
method that is called once all service providers are bound and the application is about done booting.
All you need to do is add the method and do whatever you want in it:
class MyConfiguration implements ConfigurationInterface
{
public function boot()
{
$this->container->get('db')->query('something');
}
}