|
| 1 | +# lazy-command-bundle |
| 2 | + |
| 3 | +Bundle for better dependency injection with Symfony commands |
| 4 | + |
| 5 | +## Installing |
| 6 | + |
| 7 | +As simple as running a command in your terminal: |
| 8 | + |
| 9 | +`composer require alchemy/lazy-command-bundle`. |
| 10 | + |
| 11 | +Of course, you will also need to have [Composer](https://getcomposer.org/) installed beforehand. |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +Just add the bundle to your kernel. For now, it's zero-config, hassle free proxy goodness. |
| 16 | + |
| 17 | +## Background |
| 18 | + |
| 19 | +Using commands as services in Symfony can be quite a pain as soon as your dependencies start using connections |
| 20 | +to various resources (database, message queues, what not...), as all commands have to be instantiated in order |
| 21 | +for a Symfony Console application to run properly. |
| 22 | + |
| 23 | +This bundle is an attempt to solve this by replacing all the service dependencies of your commands by lazy proxies |
| 24 | +(using the excellent ProxyManager library), ensuring that external resources are only acquired as needed. |
| 25 | + |
| 26 | +Another approach could be to mark the dependencies of your commands as lazy using Symfony DI's built-in features, |
| 27 | +but this approach is not optimal when your dependencies are re-used in multiple contexts (ie, a service that |
| 28 | +is used both by a console application and a web application) and a proxy is not required (or worse, is a performance |
| 29 | +penalty) in all contexts. |
| 30 | + |
| 31 | +## How it works |
| 32 | + |
| 33 | +The bundle adds a compiler pass to your service container's build process, replacing all service references by lazy |
| 34 | +proxies for services that are tagged with the `console.command` tag. |
| 35 | + |
| 36 | +There is no performance penalty in HTTP contexts (unless you actually use your commands in your controllers, but you |
| 37 | +probably have bigger issues to worry about then). |
| 38 | + |
| 39 | +There are no benchmarks for now, but proxifying your command dependencies is probably cheaper than actually acquiring |
| 40 | +external resources that won't be used. |
| 41 | + |
| 42 | +## Todo |
| 43 | + |
| 44 | +- Add configuration settings to "lazify" commands on an on-demand basis |
| 45 | +- Proxify dependencies used in setter injections |
| 46 | +- Add LICENCE (which is MIT in case you're wondering) |
| 47 | +- Add tests |
| 48 | +- Add CI (Travis, Scrutinizer) |
| 49 | +- Add badges |
| 50 | +- Add library to packagist |
| 51 | +- Create first release |
| 52 | + |
| 53 | + |
| 54 | + |
0 commit comments