https://github.com/bpolaszek/containeraware-bundle
Symfony Bundle: A ContainerAware compiler pass to automatically inject your service container.
https://github.com/bpolaszek/containeraware-bundle
Last synced: 3 months ago
JSON representation
Symfony Bundle: A ContainerAware compiler pass to automatically inject your service container.
- Host: GitHub
- URL: https://github.com/bpolaszek/containeraware-bundle
- Owner: bpolaszek
- License: mit
- Archived: true
- Created: 2017-07-24T14:11:23.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-11-07T07:39:22.000Z (about 1 year ago)
- Last Synced: 2025-01-10T09:59:34.169Z (about 1 year ago)
- Language: PHP
- Size: 20.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://packagist.org/packages/bentools/containeraware-bundle)
[](https://packagist.org/packages/bentools/containeraware-bundle)
[](https://travis-ci.org/bpolaszek/containeraware-bundle)
[](https://scrutinizer-ci.com/g/bpolaszek/containeraware-bundle)
[](https://packagist.org/packages/bentools/containeraware-bundle)
This Symfony bundle automatically injects the **Service Container** into all your services that implement `Symfony\Component\DependencyInjection\ContainerAwareInterface`.
> [!IMPORTANT]
> This repository is no longer maintained and may be removed in a near future. You may consider creating a fork if you still require it.
Installation
------------
> composer require bentools/containeraware-bundle
Then, just add this bundle to your `AppKernel`.
```php
# app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new BenTools\ContainerAwareBundle\ContainerAwareBundle(), // Insert at the bottom of the array for better performances
];
return $bundles;
}
}
```
And that's it! You're ready to go. No need to edit any configuration file.
You no longer need to explicitely call `$service->setContainer($container)` in your `services.yml` or `services.xml` files.
Example usage
-------------
```php
# src/AppBundle/Services/DummyService.php
namespace AppBundle\Services;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
class DummyService implements ContainerAwareInterface
{
use ContainerAwareTrait;
public function doSomethingAwesome()
{
$doctrine = $this->container->get('doctrine');
// do awesome stuff
}
}
```
```yaml
# app/config/services.yml
services:
dummy.service:
class: AppBundle\Services\DummyService
#calls:
#- [ 'setContainer', [ '@service_container' ] ] # // Not needed anymore
```
Compatibility
-------------
This bundle has been successfully tested against Symfony **2.7** to **3.3** / PHP **5.3** to **7.1**.
See [Travis builds](https://travis-ci.org/bpolaszek/containeraware-bundle) for more information.
Tests
-----
> ./vendor/bin/phpunit