Setup
Add the following lines to the plugins bootstrap file:
$plugin = new \CEKW\WpPlugin\Plugin(__FILE__);
$plugin
->addServices([
...
])
->bootstrap();
Adding custom dependencies to the injector
$injector = new Injector();
$injector->alias(LoggerInterface::class, Logger::class);
$injector->define(Logger::class, [
':logDirectory' => WP_CONTENT_DIR
]);
class MyCustomConfig
{
public function __construct(
public readonly string $customOption;
) {}
}
$injector->share(new MyCustomConfig('value'));
$plugin = new \CEKW\WpPlugin\Plugin(__FILE__, $injector);
...
Making the URL generator accessible to other plugins or themes.
...
global $cekwAppUrlGenerator;
$cekwAppUrlGenerator = $plugin->getUrlGenerator();
function get_url_generator() {
global $cekwAppUrlGenerator;
return $cekwAppUrlGenerator;
}