|
|
|
@ -72,13 +72,13 @@ use yii\helpers\ArrayHelper;
|
|
|
|
|
* } |
|
|
|
|
* |
|
|
|
|
* $container = new Container; |
|
|
|
|
* $container->set('yii\db\Connection', [ |
|
|
|
|
* $container->set(\yii\db\Connection::class, [ |
|
|
|
|
* 'dsn' => '...', |
|
|
|
|
* ]); |
|
|
|
|
* $container->set('app\models\UserFinderInterface', [ |
|
|
|
|
* 'class' => 'app\models\UserFinder', |
|
|
|
|
* $container->set(\app\models\UserFinderInterface::class, [ |
|
|
|
|
* 'class' => \app\models\UserFinder::class, |
|
|
|
|
* ]); |
|
|
|
|
* $container->set('userLister', 'app\models\UserLister'); |
|
|
|
|
* $container->set('userLister', \app\models\UserLister::class); |
|
|
|
|
* |
|
|
|
|
* $lister = $container->get('userLister'); |
|
|
|
|
* |
|
|
|
@ -191,20 +191,20 @@ class Container extends Component
|
|
|
|
|
* |
|
|
|
|
* ```php |
|
|
|
|
* // register a class name as is. This can be skipped. |
|
|
|
|
* $container->set('yii\db\Connection'); |
|
|
|
|
* $container->set(\yii\db\Connection::class); |
|
|
|
|
* |
|
|
|
|
* // register an interface |
|
|
|
|
* // When a class depends on the interface, the corresponding class |
|
|
|
|
* // will be instantiated as the dependent object |
|
|
|
|
* $container->set('yii\mail\MailInterface', 'yii\swiftmailer\Mailer'); |
|
|
|
|
* $container->set(\yii\mail\MailInterface::class, \yii\swiftmailer\Mailer::class); |
|
|
|
|
* |
|
|
|
|
* // register an alias name. You can use $container->get('foo') |
|
|
|
|
* // to create an instance of Connection |
|
|
|
|
* $container->set('foo', 'yii\db\Connection'); |
|
|
|
|
* $container->set('foo', \yii\db\Connection::class); |
|
|
|
|
* |
|
|
|
|
* // register a class with configuration. The configuration |
|
|
|
|
* // will be applied when the class is instantiated by get() |
|
|
|
|
* $container->set('yii\db\Connection', [ |
|
|
|
|
* $container->set(\yii\db\Connection::class, [ |
|
|
|
|
* 'dsn' => 'mysql:host=127.0.0.1;dbname=demo', |
|
|
|
|
* 'username' => 'root', |
|
|
|
|
* 'password' => '', |
|
|
|
@ -214,7 +214,7 @@ class Container extends Component
|
|
|
|
|
* // register an alias name with class configuration |
|
|
|
|
* // In this case, a "class" element is required to specify the class |
|
|
|
|
* $container->set('db', [ |
|
|
|
|
* 'class' => 'yii\db\Connection', |
|
|
|
|
* 'class' => \yii\db\Connection::class, |
|
|
|
|
* 'dsn' => 'mysql:host=127.0.0.1;dbname=demo', |
|
|
|
|
* 'username' => 'root', |
|
|
|
|
* 'password' => '', |
|
|
|
|