For example,
php
a class name
$locator->set('cache', 'yii\caching\FileCache');
a configuration array
$locator->set('db', [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=127.0.0.1;dbname=demo',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
]);
an anonymous function
$locator->set('cache', function ($params) {
return new \yii\caching\FileCache;
});
an instance
$locator->set('cache', new \yii\caching\FileCache);
If a component definition with the same ID already exists, it will be overwritten.