简体   繁体   English

Symfony3扩展了AppKernel

[英]Symfony3 extends AppKernel

I am recently working on a project where i build my own Bundle inside the vendor. 最近,我正在一个项目中,在供应商内部构建自己的Bundle。 This is working out great. 这很好。 I also managed to add my config dependencies and other bundle dependencies. 我还设法添加了我的配置依赖项和其他捆绑包依赖项。

My problem is: 我的问题是:

How can i extend the Kernel inside app/AppKernel with my own Kernel. 如何使用自己的内核在app/AppKernel扩展内核。 The Kernel i want to use is inside the vendor (Inside the Bundle i have created). 我要使用的内核在供应商内部(在我创建的捆绑软件内部)。

What i want to accomplish is: 我要完成的是:

My bundle is "connected" with several domains (one Symfony installation for multiple projects). 我的捆绑包与多个域“连接”(一个Symfony安装用于多个项目)。 There will be a lot of updates in the future, where i might add new Bundle dependencies. 将来会有很多更新,我可能会在其中添加新的Bundle依赖项。 I don't want to add them to all my projects one by one. 我不想将它们一个接一个地添加到我的所有项目中。

What i have tried 我尝试过的

I have tried setting up symfony-bundles/bundle-dependency and i've followed this issue Bundles and Dependencies but it seems like you still have to edit the main AppKernel afterwards. 我已经尝试设置symfony-bundles/bundle-dependency并且已经关注了这个问题Bundles and Dependencies,但是看来您以后仍然需要编辑主AppKernel

Are there any other suggestions? 还有其他建议吗?

I don't think there's an out-of-the-box solution that will automatically add bundles installed by Composer to AppKernel . 我认为没有现成的解决方案可以将Composer安装的捆绑包自动添加到AppKernel But if your bundle dependencies are always specified by a single package, you could try something like this: 但是,如果您的捆绑包依赖性始终由单个软件包指定,则可以尝试执行以下操作:

  • Have a single designated class with a method that returns bundles that you always want to include, for example: 具有一个指定的类,该类的方法返回您始终希望包含的包,例如:

     class MyKernelExtension { public static function getBundles() { return [ new MyBundle(), new MyOtherBundle, // ... ]; } } 
  • Use this method in AppKernel::registerBundles() : AppKernel::registerBundles()使用此方法:

     class AppKernel extends Kernel { public function registerBundles() { $bundles = [ new Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle(), // ... ]; $bundles = array_merge($bundles, MyKernelExtension::getBundles()); return $bundles; } } 

You only have to add one line to AppKernel , and you never have to change it. 您只需要向AppKernel添加一行,而AppKernel更改它。 Then every time you change MyKernelExtension in your Composer-installable package, you only update it, and the bundles will be registered. 然后,每次在可安装Composer的软件包中更改MyKernelExtension时,只需对其进行更新,然后捆绑软件将被注册。

I'm not aware of any other solutions, however this one seems simple enough. 我没有其他解决方案,但是这个解决方案似乎很简单。

As far as I understood, you did not start the development of the bundle rightly. 据我了解,您没有正确开始捆绑软件的开发。 It is a bad idea copy your bundle to vendor folder. 将您的捆绑包复制到供应商文件夹是个坏主意。 It would be proper to use native dependencies like a Packagist or other related things. 使用像Packagist之类的本地依赖项或其他相关的东西是适当的。 The right way for installing bundle must be one command like a composer req yourBundle and add one line to your AppKernel::registerBundles() described earlier. 正确安装软件包的方法必须是一个命令,例如composer req yourBundle并在前面所述的AppKernel::registerBundles()中添加一行。 This will save you trouble transferring updates to other instances and you will only have enough composer update command on each project. 这样可以避免将更新传输到其他实例的麻烦,并且每个项目上只有足够的composer update命令。

Please look these links, it might help. 请查看这些链接,可能会有所帮助。

Creating your very own Composer Package 创建自己的Composer程序包

Creating your first Composer/Packagist package 创建您的第一个Composer / Packagist软件包

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

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