New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First step to addons support #672
Conversation
To uz nejspis nema vyznam v dnesnim svete extensions :) |
There has been huge discussion on this topic - http://forum.nette.org/cs/10875-nette-addons-konvence-a-architektura-aplikace?p=2. I also agree with closing, because all these things can be more flexibly accomplished via |
First of all I suggest to all of you to carefully read the above mentioned topic. Then to study at least Symfony, RoR or any other framework that has some solution to addons and modularity. I agree with @enumag that the events can be solved other way (but one can find that by reading the topic and it's not the most important thing about this PR). I totally disagree with all of you about the extensions. Now it makes much more sense than ever before. The new addon site is in progress, people started to make new extensions, datagrids, etc., but there's absolutely no support for this from the framework side, there's a huge mess in the extensions and their installation is usually complicated and "dirty". Compiler extension is a very nice thing but it's NOT a solution to addons and modularity. Again, it's all already discussed here http://forum.nette.org/cs/10875-nette-addons-konvence-a-architektura-aplikace and until this is solved, Nette is just a mixture of a very nice tools but not a mature framework. |
@JanJakes You can easily make an extension from THIS very PR you know. In any case it would be better to register addons in neon than Compiler::registerAddons which is easy to do by extention. Also if addon has it's own presenters etc., how are CSS, JS, Images, etc. solved? It was surely discussed before, I just don't have time to read the entire topic about this. |
@enumag This PR is just a "first step" and a kind of RFC - something that came from the discussion on the forums and is intended to be discussed. It is (probably) at the moment not possible to make such thing just an extension. Simply because of the things that are mentioned on the forums and that you've mentioned too - Compiler extension is just a complier extension, when we need some solution for any type of addon, we need to have access to it's CSS, JS, etc., routing on it's Presenters, etc. Solutions to these are discussed in the topic. CSS, JS, etc. is a very complicated problem. What I've proposed was the first and most basic step - each addon would provide paths to it's assets in some standardized or recommended way. Then it would be up to anybody if he would just copy them to public directory, use WebLoader or Assetic, etc. The point was just to define some basic rules, the smallest possible set of rules that are necessary and leave the rest on the addons. For details and solutions to assets see the forum, Symfony, Assetic or Pythons's Webassets. |
991ba1a
to
e23de7a
Compare
Almost 2 years passed... this is now solved by CompilerExtension, composer and bower. |
I don't like the proposed solution. |
@TomasVotruba I agree that this issue is already outdated but I would argue about that "this is now solved". Nette is still missing a complete, unified, and easy-to-use addon/package support even though compiler extensions are very powerful. However, I agree that this solution is not the right way. Something like http://forum.nette.org/en/18888-extending-extensions-solid-modular-concept is a much better way to go. @fprochazka The funny thing is that the solution is from like 90% based on yours :) Although I was initially inspired by Symfony, the final solution came mostly from Kdyby at that time. Anyway, you're right about closing this issue. |
@JanJakes Thank you! |
This is a first step to add addons support to Nette, no BC breaks.
It solves the definition, naming and installation of addons and we can have access to it's directory (for resources, etc.).
Next steps should be:
How does it work at the moment?
Every addon is a subclass of
Nette\Addons\Addon
. It has some methods to resolve it's name and path. The compile() function is used to register compiler extensions. The basic approach is similar to Kdyby, but simplified.1. Addon definition
Every addon must be a subclass of Nette\Addons\Addon.
The simplest addon class can be empty:
The addon's creator can also specify it's default name:
User of the addon can always overwrite its name (see installation).
We can register compiler extensions in the compile function:
We can also use Nette\Application\Application events in the addon:
2. Installation (in bootstrap.php)
Addon can be also named by user:
If addon is not named by user, it can have a default name given by it's creator. If there is no one, the addon will take the name from the class name (ConsoleAddon will be "console").
3. Compiler extensions
Compiler extension can be registered in the addon class in a function compile(). The suggested convention is using the addon name as a prefix:
All the service definitions should be named with $this->prefix().
If we use this conventions, user is able to rename the prefix of addons services as he needs.
This could, however, bring a problem when we create an addon that refers some services from another addon. To find out the name that user has chosen for addon we can use the AddonContainer:
Inside a compiler extension class we can simply use:
4. Using addons, AddonManager
Many addons will add it's function to the DI container as a new services - then we can use them as any other services.
If we need to get some information about the addon (name, path, etc.), we can use service
addonManager
. For example in a Presenter class:Or:
Etc. (See the AddonManager class methods.)
Then we can get desired information: