Download the PHP package matthiasnoback/lazy-services-bundle without Composer
On this page you can find all versions of the php package matthiasnoback/lazy-services-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download matthiasnoback/lazy-services-bundle
More information about matthiasnoback/lazy-services-bundle
Files in matthiasnoback/lazy-services-bundle
Package lazy-services-bundle
Short Description Bundle for marking services and arguments as "lazy"
License MIT
Homepage http://github.com/matthiasnoback/LazyServicesBundle
Informations about the package lazy-services-bundle
LazyServicesBundle
By Matthias Noback
Installation
Run:
php composer.phar require matthiasnoback/lazy-services-bundle 0.2.*
Then register the bundle in /app/AppKernel.php
:
<?php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Matthias\LazyServicesBundle\MatthiasLazyServicesBundle,
);
}
}
Usage
Lazy arguments
This bundle allows you to mark services as lazy by adding tags to arguments that refer to them:
<service id="some_service" class="...">
<argument type="service" id="mailer" key="mailer" />
<tag name="lazy_argument" key="mailer" />
</service>
The argument key can be a string (like in the example above), or a number, indicating the index of the argument (starting with 0):
<service id="some_service" class="...">
<argument type="service" id="event_dispatcher" /><!-- key is 0 -->
<argument type="service" id="mailer" /><!-- key is 1 -->
<tag name="lazy_argument" key="1" />
</service>
Both examples will effectively convert the mailer
service to a lazy-loading
service.
When the referenced service does not exist, it will be skipped silently.
Lazy services by configuration
For your convenience, this bundle also allows you to mark services as lazy by adding its service id to a list of lazy services in your application configuration:
# in config.yml:
matthias_lazy_services:
lazy_service_ids:
- mailer
- ...
When the referenced service does not exist, it will be skipped silently.