Skip to content

Zend Framework 2 - Lazy Factory - Kickstarter (for ZF 2.4)

No blabla, just how you do it with zend framework 2.4.

#add following line to your composer.json
"ocramius/proxy-manager": "1.0.*",

composer update

#add following lines to your module.config.php
'lazy_services' => [
    'class_map' => [
        \My\Class::class => \My\Class::class
    ]
],
'service_manager' => [
    'delegators' => [
        \My\Class::class => [
            \Zend\ServiceManager\Proxy\LazyServiceFactory::class
        ]
    ],
    'factories' => [
        \My\Class::class => \My\ClassFactory::class,
        \Zend\ServiceManager\Proxy\LazyServiceFactory::class => \Zend\ServiceManager\Proxy\LazyServiceFactoryFactory::class
    ]
]

Thats it.

Useful links are a gist from a closed issue and somehow an official howto (maybe working with zend framework greater 2.4).