Final Class Yiisoft\Test\Support\Container\SimpleContainer
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Psr\ |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| get() | Yiisoft\ |
|
| has() | Yiisoft\ |
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
?? static function (string $id): mixed {
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];
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.