theofidry / sfcontext-bundle
A context to access statically to the symfony container.
Installs: 2 151
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 3
Open Issues: 1
Type:symfony-bundle
Requires
- symfony/framework-bundle: ^3.4 || ^4.0 || ^5.0
Requires (Dev)
- phpunit/phpunit: ^6.4
- symfony/yaml: ^3.4 || ^4.0 || ^5.0
This package is auto-updated.
Last update: 2020-09-12 18:16:08 UTC
README
A dead simple bundle to be able to access the Symfony Container statically.
Install
You can use Composer to install the bundle in your project:
composer require theofidry/sfcontext-bundle
Then, enable the bundle by updating your app/AppKernel.php
file to enable the bundle:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Fidry\SfContextBundle\SfContextBundle(), ); return $bundles; }
Usage
There are two cases where you might use this bundle:
- If you don't like dependency injection
- For quick & dirty debugging where you can't afford to do a dump
class DummyService { public function foo() { // Do something SfContext::get('logger')->debug('it worked'); // Do something else } }
Credits
I got the original idea from Laravel facades although the idea is actually not new and you can find it in the Symfony world as sfContext and which has been ported to Symfony 2.x with sfContextBundle.