Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\Core\DI;
6
7use PeServer\Core\DI\IScopedDiContainer;
8use PeServer\Core\Throws\DiContainerArgumentException;
9use PeServer\Core\Throws\DiContainerException;
10use Psr\Container\ContainerInterface;
11
12/**
13 * DIコンテナ。
14 */
15interface IDiContainer extends ContainerInterface
16{
17    #region ContainerInterface
18    #endregion
19
20    #region function
21
22    /**
23     * 指定したIDが登録されているか。
24     *
25     * @param class-string|non-empty-string $id
26     * @return bool
27     */
28    public function has(string $id): bool; //@phpstan-ignore-line [TYPE_INTERFACE]
29
30    /**
31     * 指定したIDのオブジェクトを取得。
32     *
33     * @template T of object
34     * @param class-string|class-string<T>|non-empty-string $id
35     * @return object
36     * @phpstan-return ($id is class-string<T> ? T: object)
37     * @throws DiContainerException
38     */
39    public function get(string $id): object; //@phpstan-ignore-line [TYPE_INTERFACE]
40
41    /**
42     * クラス生成。
43     *
44     * @template T of object
45     * @param class-string|class-string<T>|non-empty-string $idOrClassName
46     * @param array<int|string,mixed> $arguments 生成パラメータ指定。
47     *  * int: 引数位置(0基点)。負数の場合で 0 に近い項目で割り当て可能(非`null`)なパラメータであれば順に消費されていく。
48     *  * string: 先頭が `$` で始まる場合は引数名、それ以外は型名と判断。型名の場合は一致するごとに消費されていく。
49     *  * 引数位置指定が優先される
50     *  * 未指定パラメータはDIコンテナ側で生成する
51     * @return object
52     * @phpstan-return ($idOrClassName is class-string<T> ? T: object)
53     * @throws DiContainerArgumentException パラメータ指定さている場合に対象ID($idOrClassName)がシングルトン・値の場合に投げられる。
54     */
55    public function new(string $idOrClassName, array $arguments = []): object;
56
57    /**
58     * コールバックを実施。
59     *
60     * @param callable $callback
61     * @param array<int|string,mixed> $arguments `new` を参照。
62     * @return mixed
63     */
64    public function call(callable $callback, array $arguments = []): mixed;
65
66    /**
67     * 現在のDIコンテナを複製。
68     *
69     * @return IScopedDiContainer
70     */
71    public function clone(): IScopedDiContainer;
72
73    #endregion
74}