Final Class Yiisoft\Test\Support\Container\SimpleContainer
| Inheritance | Yiisoft\Test\Support\Container\SimpleContainer |
|---|---|
| Implements | Psr\Container\ContainerInterface |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Test\Support\Container\SimpleContainer | |
| get() | Yiisoft\Test\Support\Container\SimpleContainer | |
| has() | Yiisoft\Test\Support\Container\SimpleContainer |
Method Details
| public mixed __construct ( array $definitions = [], Closure|null $factory = null, Closure|null $hasCallback = null ) | ||
| $definitions | array | |
| $factory | Closure|null |
Should be closure that works like ContainerInterface::get(string $id): mixed |
| $hasCallback | Closure|null |
Should be closure that works like ContainerInterface::has(string $id): bool |
public function __construct(
private array $definitions = [],
?Closure $factory = null,
?Closure $hasCallback = null
) {
$this->factory = $factory ??
/** @return mixed */
static function (string $id) {
throw new NotFoundException($id);
};
$this->hasCallback = $hasCallback ??
function (string $id): bool {
try {
$this->get($id);
return true;
} catch (NotFoundException) {
return false;
}
};
}
| public mixed get ( mixed $id ) | ||
| $id | mixed | |
public function get($id)
{
if (!array_key_exists($id, $this->definitions)) {
$this->definitions[$id] = ($this->factory)($id);
}
return $this->definitions[$id];
}
Signup or Login in order to comment.