Skip to content

Commit

Permalink
Update instructions for adding custom compiler pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Acker committed Jun 1, 2016
1 parent 39bd5f9 commit 81dd781
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
```

0 comments on commit 81dd781

Please sign in to comment.