ocramius / ocra-di-compiler
Zend Framework 2 Module that compiles Zend\Di definitions to speed up ZF2 applications
Installs: 1 566
Dependents: 0
Suggesters: 1
Security: 0
Stars: 24
Watchers: 3
Forks: 4
Open Issues: 2
Requires
- php: >=5.3.3
- zendframework/zendframework: >=2.0.0beta4
This package is auto-updated.
Last update: 2022-02-01 12:20:49 UTC
README
A compiler module to make Zend\Di\Di
based applications blazing fast!
Requirements
- ZendFramework 2.
- Any application similar to the ZendSkeletonApplication.
Installation
- Add
"ocramius/ocra-di-compiler": "dev-master"
to yourcomposer.json
- Run
php composer.phar install
- Enable the module in your
config/application.config.php
by addingOcraDiCompiler
tomodules
or
php composer.phar ocramius/ocra-di-compiler
Functionality
OcraDiCompiler interacts with the bootstrap process of your application by trying to write a compiled Zend\Di\Di
class
into your data
directory.
The compiled Di container will be available after the bootstrap
event of your application. Before that, any attempt
to access Di will fetch the default one.
You can customize where the compiled Di class will be written (and from where it will be read) by overriding the values
in config/module.config.php
in your own config file in the config/autoload
directory.
Performance comparison
Given a default setup of an application with doctrine/DoctrineORMModule
enabled and following class:
<?php class MyClass { public function __construct(\Doctrine\ORM\EntityManager $em) { } }
following code
<?php $serviceManager->get('Application')->bootstrap(); $serviceManager->get('Di')->get('MyClass');
should be noticeably faster (please leave me your feedback and your personal results!).
Credits
Many thanks to Sascha Oliver Prolic, who wrote the implementation of the DiProxyGenerator
and patiently waited for me to get this module implemented