yii\di\Instance::of PHP Method

of() public static method

Creates a new Instance object.
public static of ( string $id ) : Instance
$id string the component ID
return Instance the new Instance object.
    public static function of($id)
    {
        return new static($id);
    }

Usage Example

 public function testOf()
 {
     $container = new Container();
     $className = Component::className();
     $instance = Instance::of($className, $container);
     $this->assertTrue($instance instanceof Instance);
     $this->assertTrue($instance->get() instanceof Component);
     $this->assertTrue(Instance::ensure($instance, $className) instanceof Component);
     $this->assertTrue($instance->get() !== Instance::ensure($instance, $className));
 }
All Usage Examples Of yii\di\Instance::of