Test Failed
Push — lazy-services ( 2f8c8b...8212a3 )
by Dmitriy
16:14 queued 13:07
created

ContainerConfig::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Di;
6
7
/**
8
 * Container configuration.
9
 */
10
final class ContainerConfig implements ContainerConfigInterface
11
{
12
    private array $definitions = [];
13
    private array $providers = [];
14
    private array $tags = [];
15
    private bool $validate = true;
16
    private array $delegates = [];
17
    private bool $useStrictMode = false;
18
19
    private function __construct()
20
    {
21
    }
22
23
    public static function create(): self
24
    {
25
        return new self();
26
    }
27
28
    /**
29
     * @param array $definitions Definitions to put into container.
30
     */
31
    public function withDefinitions(array $definitions): self
32
    {
33
        $new = clone $this;
34
        $new->definitions = $definitions;
35
        return $new;
36
    }
37
38
    public function getDefinitions(): array
39
    {
40
        return $this->definitions;
41
    }
42
43
    /**
44
     * @param array $providers Service providers to get definitions from.
45
     */
46
    public function withProviders(array $providers): self
47
    {
48
        $new = clone $this;
49
        $new->providers = $providers;
50
        return $new;
51
    }
52
53
    public function getProviders(): array
54
    {
55
        return $this->providers;
56
    }
57
58
    /**
59
     * @param array $tags Tagged service IDs. The structure is `['tagID' => ['service1', 'service2']]`.
60
     */
61
    public function withTags(array $tags): self
62
    {
63
        $new = clone $this;
64
        $new->tags = $tags;
65
        return $new;
66
    }
67
68
    public function getTags(): array
69
    {
70
        return $this->tags;
71
    }
72
73
    /**
74
     * @param bool $validate Whether definitions should be validated immediately.
75
     */
76
    public function withValidate(bool $validate): self
77
    {
78
        $new = clone $this;
79
        $new->validate = $validate;
80
        return $new;
81
    }
82
83
    public function shouldValidate(): bool
84
    {
85
        return $this->validate;
86
    }
87
88
    /**
89
     * @param array $delegates Container delegates. Each delegate is a callable in format
90
     * `function (ContainerInterface $container): ContainerInterface`. The container instance returned is used
91
     * in case a service can not be found in primary container.
92
     */
93
    public function withDelegates(array $delegates): self
94
    {
95
        $new = clone $this;
96
        $new->delegates = $delegates;
97
        return $new;
98
    }
99
100
    public function getDelegates(): array
101
    {
102
        return $this->delegates;
103
    }
104
105
    /**
106
     * @param bool $useStrictMode If the automatic addition of definition when class exists and can be resolved
107
     * is disabled.
108
     */
109
    public function withStrictMode(bool $useStrictMode): self
110
    {
111
        $new = clone $this;
112
        $new->useStrictMode = $useStrictMode;
113
        return $new;
114
    }
115
116
    public function useStrictMode(): bool
117
    {
118
        return $this->useStrictMode;
119
    }
120
}
121