Yii source code-ServiceLocator)

Source: Internet
Author: User
: This article mainly introduces the Yii source code-ServiceLocator. For more information about PHP tutorials, see. The objective of SL is decoupling, and it is very suitable for applications based on services and components.

Service Locator acts as a runtime linker. you can dynamically modify the services to be selected for a class at runtime without having to make any modifications to the class.

A class can be used to increase, decrease, and replace services in a targeted manner during running, so as to get a certain degree of optimization.

This completely decouples service providers and service users to facilitate independent testing and code reuse across frameworks.

Basic functions

In Yii, SL consistsYii \ di \ ServiceLocatorImplementation

Class ServiceLocator extends Component {// private $ _ components = [] for cache services, components, and other instances; // Save the definition of services and components, which is usually a configuration array, it can be used to create a specific instance private $ _ definitions = []; // overload getter so that the access service and component have the same attributes as the access class. // Retains the function public function _ get ($ name) {}} of the original Component getter ){}}

Data structure

SL provides methods for registering services and components.

$ _ Components is used to cache components or service instances in SL and can be read/written.

Reference

The above introduces the Yii Source Code explanation-Service Locator, which includes some content and hopes to help friends who are interested in PHP tutorials.

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.