yii\di\Container::setDefinitions PHP Метод

setDefinitions() публичный Метод

Registers class definitions within this container.
См. также: set() to know more about possible values of definitions
С версии: 2.0.11
public setDefinitions ( array $definitions )
$definitions array array of definitions. There are two allowed formats of array. The first format: - key: class name, interface name or alias name. The key will be passed to the [[set()]] method as a first argument `$class`. - value: the definition associated with `$class`. Possible values are described in [[set()]] documentation for the `$definition` parameter. Will be passed to the [[set()]] method as the second argument `$definition`. Example: ```php $container->setDefinitions([ 'yii\web\Request' => 'app\components\Request', 'yii\web\Response' => [ 'class' => 'app\components\Response', 'format' => 'json' ], 'foo\Bar' => function () { $qux = new Qux; $foo = new Foo($qux); return new Bar($foo); } ]); ``` The second format: - key: class name, interface name or alias name. The key will be passed to the [[set()]] method as a first argument `$class`. - value: array of two elements. The first element will be passed the [[set()]] method as the second argument `$definition`, the second one — as `$params`. Example: ```php $container->setDefinitions([ 'foo\Bar' => [ ['class' => 'app\Bar'], [Instance::of('baz')] ] ]); ```
    public function setDefinitions(array $definitions)
    {
        foreach ($definitions as $class => $definition) {
            if (count($definition) === 2 && array_values($definition) === $definition) {
                $this->set($class, $definition[0], $definition[1]);
                continue;
            }
            $this->set($class, $definition);
        }
    }