简体   繁体   English

Symfony2捆绑软件作为插件

[英]Symfony2 bundle as a plugin

Consider situation where I have some default bundle that hypothetically create some empty page with menu on left and some content (if there is any). 考虑一下我有一些默认捆绑包的情况,这些捆绑包假设会创建一些带有左侧菜单的空白页和一些内容(如果有)的空白页。 Then I create a new bundle and I normally turn it on in AppKernel. 然后创建一个新的包,通常在AppKernel中将其打开。 Now should magic start: bundle by his own (no need to add any options in default bundle etc.) hooks up and creates his menu entry (and if chosen, renders his content). 现在魔术应该开始了:自己捆绑(无需在默认捆绑中添加任何选项等)进行连接并创建其菜单项(如果选择,则呈现其内容)。 How should I do this, is there any proper way to do this? 我应该怎么做,有什么适当的方法吗? What if I want to have multiple "hooks", for example, adding also new form in user profile edit, or adding new tab on some other place? 如果我想拥有多个“钩子”,例如,在用户个人资料编辑中添加新表单,或在其他地方添加新标签,该怎么办?

I'm thinking about looking for some "initialize bundle event" that I could listen to and pass data thru it. 我正在考虑寻找一些“初始化捆绑事件”,我可以监听并通过它传递数据。 But maybe there is better solution. 但是也许有更好的解决方案。 I would love to see your ideas :) 我很乐意看到您的想法:)

Looking at the initializeBundles method of the Kernel , it doesn't look easy or intended to dynamically add bundles during the bootup process. 查看KernelinitializeBundles方法,在启动过程中看起来并不容易,也不打算动态添加捆绑。

However, the AppKernel.php file is on the forefront, it is an override of Kernel and can be customized to supply a dynamic set of bundles to the implemented registerBundles method. 但是,AppKernel.php文件位于最前面,它是对Kernel的替代,可以自定义以向实现的registerBundles方法提供动态的捆绑包集。

You will need to make sure the imported content is properly added to the autoloader, but avoid modifying the distribution source at runtime, try to make it as imported as possible. 您需要确保已将导入的内容正确添加到自动加载器中,但是要避免在运行时修改分发源,请尝试使其尽可能地导入。

I don't want to go into great detail on the technicalities as I have not done this myself and it will require a lot of experimentation. 我不想详细介绍技术性,因为我自己还没有做过,这需要大量的实验。 I do know that Drupal 8 uses Symfony2 and has its own plugin system, but I don't think it takes bundles as plugins. 我确实知道Drupal 8使用Symfony2并拥有自己的插件系统,但是我不认为它需要捆绑软件作为插件。

If you manage to pull this off I suspect it will allow 100% integration between the application and the plugins, but just be aware that it also allows 100% overriding access to said plugins. 如果您设法做到这一点,我怀疑它将允许应用程序和插件之间100%集成,但是请注意,它还允许100%覆盖对所述插件的访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM