Skip to content

Commit 81dd781

Browse files
author
Jon Acker
committed
Update instructions for adding custom compiler pass
1 parent 39bd5f9 commit 81dd781

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,31 @@ To provide dependencies to other classes after they are instantiated, in additio
193193
parent::__construct();
194194
}
195195
```
196+
197+
### Registering your own compiler pass
198+
199+
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.
200+
201+
Create a Magento observer and configure it to listen to the `symfony_container_before_container_generator` Magento event.
202+
Update this observer to inject the custom compiler pass into the generator config, as shown below:
203+
204+
```php
205+
class Inviqa_DependencyInjection_Model_Observer
206+
{
207+
/** @var CustomCompilerPass */
208+
private $customCompilerPass;
209+
210+
public function __construct()
211+
{
212+
$this->customCompilerPass = new CustomCompilerPass();
213+
}
214+
215+
public function onBeforeContainerGenerator(Varien_Event_Observer $observer)
216+
{
217+
/** @var Configuration $generatorConfig */
218+
$generatorConfig = $observer->getData('generator_config');
219+
220+
$generatorConfig->addCompilerPass($this->customCompilerPass);
221+
}
222+
}
223+
```

0 commit comments

Comments
 (0)