Download the PHP package adeira/compiler-extension without Composer
On this page you can find all versions of the php package adeira/compiler-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package compiler-extension
At this moment I don't have time, energy and money to maintain this project. But it's a shame so if you depend on this project and you want to become a sponsor or develop it further please don't hesitate to contact me. Otherwise, I am not able to guarantee bright future of this repo... :)
Enhanced CompilerExtension for Nette Framework
If you have more complicated project structure with a lot of bundles (DIC extensions), it's very common that you have to setup a lot of things and it may be quite difficult. But not with this extension. All you need is to use Adeira\ConfigurableExtensionsExtension
instead of default ExtensionsExtension
like this (probably in bootstrap.php
):
This new extension will take care of configuration files in your bundles. Next if you want to use custom config for extension, just use provideConfig
method:
You don't have to extend Adeira\CompilerExtension
but there is useful helper setMapping()
(it just setups custom presenter mapping). But provideConfig
metod will work with Nette\DI\CompilerExtension
descendants as well. And why is this so interesting? Imagine you have this config in your application (added in bootstrap via Nette\DI\Compiler::addConfig
):
And now you'll add another config in your DIC extension using provideConfig
method:
What is the result? Now there are three global parameters:
As you can see your custom DIC extension has priority. Extensions parameters (ext2
) behaves exactly the same. What about services? As you can expect there will be three services:
And here comes the most interesting part. If you have a lot of extensions it's good idea to use custom config files (it's simple and easy to understand). But it may be hard to get extension configuration from neon file. In Nette\DI\CompilerExtension
descendant class you could do simply $this->getConfig()
to get configuration related to the extension, but there is no equivalent for doing this in neon. This extension adds special syntax for this case. From the previous examples there are three options related to the ext2
extension:
To get second parameter into service use this:
Remember that this is possible only if you are using custom config added by provideConfig
method. It will not work in configs added in bootstrap file (via Nette\DI\Compiler::addConfig
). This is because only under extension it's possible to get key from the right extension section (ext2.ext_key2
in this case).
Experimental features
These features are not enabled by default now (but may be enabled by default in the future). To enable experimental features now you have to register this extension differently:
At this moment there is so called GroupedNeonAdapter
. It allows you to write service definitions in NEON with grouped syntax. Before:
After:
This feature is optional and works only in NEON files provided via provideConfig
method. All classes must be registered anonymously. If it's not possible just don't use this feature.