Analyze the Ioc container by looking at unused code, and inject dependencies. Analyze the Ioc container by looking at unused code, and inject dependencies ...., ioc is not used. *** The IOC container is understood by producing super module. the interface of super module analyzes the Ioc container by looking at the code that is not used, and relies on injection ...., ioc is not used
/*** Understand the IOC container by producing super instances * // super module interface SuperModuleInterface {public function activate (array $ target );} // Super Power Module class XPower implements SuperModuleInterface {public function activate (array $ target ){//......}} class UltraBomb implements SuperModuleInterface {public function activate (array $ target ){//......}} // Superman class Superman {protected $ module; public function _ construct (SuperModuleInterface $ module) {$ this-> module = $ module ;}} /*** simple IOC Container (Super factory) */class Container {protected $ binds; protected $ instances; public function bind ($ abstract, $ concrete) {if ($ concrete instanceof Closure) {$ this-> binds [$ abstract] = $ concrete;} else {$ this-> instances [$ abstract] = $ concrete ;}} public function make ($ abstract, $ parameters = []) {if (isset ($ this-> instances [$ abstract]) {return $ this-> instances [$ abstract];} array_unshift ($ parameters, $ this); return call_user_func_array ($ this-> binds [$ abstract], $ parameters) ;}/// superfactory production script $ container = new Container (); $ container-> bind ('Superman', function ($ container, $ moduleName) {return new Superman ($ container-> make ($ moduleName) ;}); $ container-> bind ('xpower', function ($ container) {return new XPower;}); $ container-> bind ('ultrabomb', function ($ container) {return new ultrabomb ;}); // production $ superman_1 = $ container-> make ('Superman', ['xpower']); $ superman_2 = $ container-> make ('Superman ', ['ultrabomb']); print_r ($ superman_1); print_r ($ superman_2);/* Superman Object ([module: protected] => XPower Object ()) superman Object ([module: protected] => UltraBomb Object ())*/
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[Original article] core of laravel, IoC container
Laravel's core isIoC container
According to the document, it is called"Service container
As the name suggests, the container provides a series of services required in the entire framework. As a beginner, many people will have difficulties in this concept. Therefore, I plan to explain some basic content and understand the generation and solution of dependency in object-oriented development, to gradually unveil the "dependency injection" and gradually understand this magical design concept.
Most of this article uses examples to help readers understand what isIoC (control inversion)
AndDI (dependency injection)
To gain a deeper understanding of these concepts.