Content of the «Key Concepts» section:
- Class Autoloading
- Service Locator
- Dependency Injection Container
Articles section «Key Concepts»:
A dependency injection (DI) container Yii is an object that knows how to instantiate and configure objects and all their dependent objects. DI container is useful. Here we will mainly explain the usage of the DI container provided by Yii.
A service locator is an object that knows how to provide all sorts of services (or components) that an Yii application might need. Within a Yii service locator, each component exists as only a single instance, uniquely identified by an ID. You use the ID to retrieve a component from the Yii service locator.
Аutoloader Yii is installed when you include the Yii.php file.Yii relies on the class autoloading mechanism to locate and include all required class files. It provides a high-performance class autoloader that is compliant with the PSR-4 standard.
Aliases in Yii 2 are used to represent file paths or URLs so that you don't have to hard-code absolute paths or URLs in your project. An alias must start with the @ character to be differentiated from normal file paths and URLs.
Configurations are widely used in Yii when creating new objects or initializing existing objects. Configurations usually include the class name of the object being created, and a list of initial values that should be assigned to the object's properties.
Behaviors, also known as mixins, allow you to enhance the functionality of an existing [[yii\base\Component|component]] class without needing to change the class's inheritance. Behaviors are instances of [[yii\base\Behavior]], or of a yii 2 child class.
Events in Yii 2 allow you to inject custom code into existing code at certain execution points.You can attach custom code to an event so that when the event is triggered, the code gets executed automatically.
Yii introduces a base class called [[yii\base\BaseObject]] that supports defining properties based on getter and setter class methods. If a class needs that functionality, it should extend from [[yii\base\BaseObject]], or from a child class.
The three main features that components provide to other yii classes are: Properties, Events, Behaviors. Components are the main building blocks of Yii applications. Components are instances of [[yii\base\Component]], or an extended class.