Binds symfony/dependency-injection to ICanBoogie
Services can be obtained using a service reference or the container.
The following example demonstrates how services can be obtain using references:
<?php use function ICanBoogie\Service\ref; $reference = ref('a_callable_service'); $result = $reference(1, 2, 3); $reference = ref('a_service'); $service = $reference->resolve(); $service->do_something();
The following example demonstrates how a service can be obtained using the container itself:
<?php /* @var $app \ICanBoogie\Application */ /* @var $container \Symfony\Component\DependencyInjection\Container */ $container = $app->container; $service = $container->get('a_service'); $service->do_something();
Usually, ICanBoogie's components add getters to
ICanBoogie\Application instances through the
prototype system, which means you can access the initial request using
or the session using
$app->session. Services defined this way are automatically accessible through
the container as well, which means they can be used as references
ref('session') or obtained
through the container
All application config parameters are available as container parameters e.g.
Note: To avoid clashes, all application parameters are prefixed with
Services are defined using
services.yml files in
config folders. They are collected when it's
time to create the container, just like regular configuration files.
The tests included in this package showcase how
services.yml files can be defined in
default/config. Components and modules can use this feature to register their own services and
make them available to the application automatically.
The following example demonstrates how the service provider and the service container can be obtained:
<?php use ICanBoogie\Service\ServiceProvider; /* @var $proxy \ICanBoogie\Binding\SymfonyDependencyInjection\ContainerFactory */ $proxy = ServiceProvider::defined(); $container = $proxy->container;
The container is configured using
container configuration fragments:
<?php // config/container.php use ICanBoogie\Binding\SymfonyDependencyInjection\ConfigBuilder; use ICanBoogie\Binding\SymfonyDependencyInjection\Extension\ApplicationExtension; return fn(ConfigBuilder $config) => $config ->add_extension(ApplicationExtension::class) ->enable_caching();
The project is continuously tested by GitHub actions.
This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.
Please see CONTRIBUTING for details.
make test-container to create and log into the test container, then run
make test to run the
test suite. Alternatively, run
make test-coverage to run the test suite with test coverage. Open
build/coverage/index.html to see the breakdown of the code coverage.
icanboogie/bind-symfony-dependency-injection is released under the BSD-3-Clause.