Analyze the Ioc container by looking at unused code, and inject dependencies.... see the ioc_PHP tutorial.

Source: Internet
Author: User
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 containerAccording to the document, it is called"Service containerAs 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.