From 81dd7812b5e71f9a272afa818e7d67397ffb3a88 Mon Sep 17 00:00:00 2001 From: Jon Acker Date: Wed, 1 Jun 2016 13:53:57 +0100 Subject: [PATCH] Update instructions for adding custom compiler pass --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 3b655de..76e4bf7 100644 --- a/README.md +++ b/README.md @@ -193,3 +193,31 @@ To provide dependencies to other classes after they are instantiated, in additio parent::__construct(); } ``` + +### Registering your own compiler pass + +Create a [custom compiler pass](https://github.com/inviqa/magento-symfony-container/blob/master/app/code/community/Inviqa/SymfonyContainer/Model/InjectableCompilerPass.php) class in your project. + +Create a Magento observer and configure it to listen to the `symfony_container_before_container_generator` Magento event. +Update this observer to inject the custom compiler pass into the generator config, as shown below: + +```php +class Inviqa_DependencyInjection_Model_Observer +{ + /** @var CustomCompilerPass */ + private $customCompilerPass; + + public function __construct() + { + $this->customCompilerPass = new CustomCompilerPass(); + } + + public function onBeforeContainerGenerator(Varien_Event_Observer $observer) + { + /** @var Configuration $generatorConfig */ + $generatorConfig = $observer->getData('generator_config'); + + $generatorConfig->addCompilerPass($this->customCompilerPass); + } +} +```