Download the PHP package spiechu/lazy-pimple without Composer
On this page you can find all versions of the php package spiechu/lazy-pimple. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download spiechu/lazy-pimple
More information about spiechu/lazy-pimple
Files in spiechu/lazy-pimple
Package lazy-pimple
Short Description Lazy service definitions for Pimple DI container.
License MIT
Homepage https://github.com/spiechu/lazy-pimple
Informations about the package lazy-pimple
Lazy Pimple
Lazy service definitions for Pimple DI container.
Intro
When using Pimple DIC, there is sometimes need to lazy load service and instantiate it only when needed.
What's more, there is also possibility to lazy load event subscribers. (Now you'll see why \Symfony\Component\EventDispatcher\EventSubscriberInterface
has static interface).
Under the hood this library uses Proxy Manager. Object's proxy is firstly generated. Until instance method call is needed, the proxy is being used. This means even static calls don't need object's instance and are called by proxy.
Installation
Simplest way is to add "spiechu/lazy-pimple": "~0.1"
to your composer.json
.
The minimal configuration for lazy loads to work is to add two definitions to your Pimple:
In order to use ProxyManager proxy cache, LazyLoadingValueHolderFactoryFactory->getFactory()
accepts dir path to writable space where it can dump generated proxy class definitions. You can see how to do it in the full listing at the bottom of this page.
Usage
Lazy services
With use of this library, you can easy lazy load Pimple service definitions until they're needed.
Lazy event subscribers
We'll start with typical event subscriber definition.
Now by using \Pimple\ServiceProviderInterface
service provider we can transform subscribers into lazy loaded.
This way only when event actually took place, subscriber is instantiated and event handle method called.
Example Pimple service definition (taken from my "tests").
All versions of lazy-pimple with dependencies
ocramius/proxy-manager Version ~1.0|~2.0
pimple/pimple Version ~2.1|~3.0
symfony/event-dispatcher Version ~3.0|~4.0