I need some advice or some advice.
I have a core bundle with some general functionality, with many extra bundles with more specific functionality.
My core bundle, for example, is responsible for the main menu rendering its application, but I want to be able to add other bundles only bundle by registering the menu items. (End those menu items available menu items will be available, which are not necessarily really active.)
Not sure I have a solution for it, but I really think this is good.
My core bundle also includes core bundle interfaces:
namespace core bundle; Use CoreBundle \ Menu \ MenuBuilder; Interface CoreBundleInterface {public function getMenuItems (MenuBuilder $ menuItem); } So another bundle can implement this interface:
namespace the bundle; Use CoreBundle \ CoreBundleInterface; Use CoreBundle \ Menu \ MenuBuilder; Use Symfony \ Component \ HttpKernel \ Bundle \ Bundle; addItem ([ 'name' = & gt; addresses', 'label' = & gt; 'address']) class AddressBundle implements bundle CoreBundleInterface {public function getMenuItems (MenuBuilder $ menuBuilder) {$ menuBuilder- & gt extends}} I CoreBundle a MenuBuilder class walks through the registered bundles and interface calls methods:
namespace CoreBundle \ menu; Use CoreBundle \ CoreBundleInterface; Use Symfony \ Component \ DependencyInjection \ ContainerInterface; Class menubilder {Private $ item; Public Function __construct (ContainerInterface $ Container) {$ this- & gt; AddItem (['name' = & gt; 'home', 'label' => 'home']); $ Bundle = $ container- & gt; Receive ('kernel') - & gt; Matching bundle (); foreach ($ bundles as $ bundled) {if (Is_callable (array ($ Bundle, 'getMenuItems')) & amp; & amp; CoreBundleInterface instanceof $ bundled) {Call_user_func (array ($ Bundle, 'getMenuItems'), $ This); }}} ...} I tried to imagine that structure I Who:
Any sign to perform a better practice will be highly appreciated for achieving this structure.
No comments:
Post a Comment