Skip to main content

The best way to load adapter connections is through defining them in the di.php file of your project and injecting them in the classes you need.

Reference by connection id

Use the \Attlaz\Project\DI\Definition\ConnectionDefinition class in your etc/di.php file.

Get the connection id in the dashboard by signin in and going to Connections > Your connections

etc/di.php
use Attlaz\Adapter\DigitalOcean\DigitalOceanClient;
use Attlaz\Project\DI\Definition\ConnectionDefinition;

return [
DigitalOceanClient::class => new ConnectionDefinition('<adapterId>', DigitalOceanClient::class),
];

Through configuration

Alternatively you can create a configuration field that hold the connection id to use. This allows for easy changing of connections between environments.

Define in DI by configuration key, in the configuration field you define the connection id. In this case we have created a configuration field config_field and our "MyTogglRepository" expects 2 arguments.

MyTogglRepository::class => create()
->constructor(new \Attlaz\Project\DI\Definition\ConfigConnectionDefinition('<config_field>', \Attlaz\Adapter\Toggl\TogglConnection::class))
->method('setLogger', get(LoggerInterface::class)),