/var/www/html_us/wp-content/plugins/woocommerce/lib/packages/League/Container/Container.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php declare(strict_types=1);

namespace 
Automattic\WooCommerce\Vendor\League\Container;

use 
Automattic\WooCommerce\Vendor\League\Container\Definition\{DefinitionAggregateDefinitionInterfaceDefinitionAggregateInterface};
use 
Automattic\WooCommerce\Vendor\League\Container\Exception\{NotFoundExceptionContainerException};
use 
Automattic\WooCommerce\Vendor\League\Container\Inflector\{InflectorAggregateInflectorInterfaceInflectorAggregateInterface};
use 
Automattic\WooCommerce\Vendor\League\Container\ServiceProvider\{
    
ServiceProviderAggregate,
    
ServiceProviderAggregateInterface,
    
ServiceProviderInterface
};
use 
Automattic\WooCommerce\Vendor\Psr\Container\ContainerInterface;

class 
Container implements ContainerInterface
{
    
/**
     * @var boolean
     */
    
protected $defaultToShared false;

    
/**
     * @var DefinitionAggregateInterface
     */
    
protected $definitions;

    
/**
     * @var ServiceProviderAggregateInterface
     */
    
protected $providers;

    
/**
     * @var InflectorAggregateInterface
     */
    
protected $inflectors;

    
/**
     * @var ContainerInterface[]
     */
    
protected $delegates = [];

    
/**
     * Construct.
     *
     * @param DefinitionAggregateInterface|null      $definitions
     * @param ServiceProviderAggregateInterface|null $providers
     * @param InflectorAggregateInterface|null       $inflectors
     */
    
public function __construct(
        ?
DefinitionAggregateInterface      $definitions null,
        ?
ServiceProviderAggregateInterface $providers null,
        ?
InflectorAggregateInterface       $inflectors null
    
) {
        
$this->definitions $definitions ?? new DefinitionAggregate;
        
$this->providers   $providers   ?? new ServiceProviderAggregate;
        
$this->inflectors  $inflectors  ?? new InflectorAggregate;

        if (
$this->definitions instanceof ContainerAwareInterface) {
            
$this->definitions->setLeagueContainer($this);
        }

        if (
$this->providers instanceof ContainerAwareInterface) {
            
$this->providers->setLeagueContainer($this);
        }

        if (
$this->inflectors instanceof ContainerAwareInterface) {
            
$this->inflectors->setLeagueContainer($this);
        }
    }

    
/**
     * Add an item to the container.
     *
     * @param string  $id
     * @param mixed   $concrete
     * @param boolean $shared
     *
     * @return DefinitionInterface
     */
    
public function add(string $id$concrete null, ?bool $shared null) : DefinitionInterface
    
{
        
$concrete $concrete ?? $id;
        
$shared $shared ?? $this->defaultToShared;

        return 
$this->definitions->add($id$concrete$shared);
    }

    
/**
     * Proxy to add with shared as true.
     *
     * @param string $id
     * @param mixed  $concrete
     *
     * @return DefinitionInterface
     */
    
public function share(string $id$concrete null) : DefinitionInterface
    
{
        return 
$this->add($id$concretetrue);
    }

    
/**
     * Whether the container should default to defining shared definitions.
     *
     * @param boolean $shared
     *
     * @return self
     */
    
public function defaultToShared(bool $shared true) : ContainerInterface
    
{
        
$this->defaultToShared $shared;

        return 
$this;
    }

    
/**
     * Get a definition to extend.
     *
     * @param string $id [description]
     *
     * @return DefinitionInterface
     */
    
public function extend(string $id) : DefinitionInterface
    
{
        if (
$this->providers->provides($id)) {
            
$this->providers->register($id);
        }

        if (
$this->definitions->has($id)) {
            return 
$this->definitions->getDefinition($id);
        }

        throw new 
NotFoundException(
            
sprintf('Unable to extend alias (%s) as it is not being managed as a definition'$id)
        );
    }

    
/**
     * Add a service provider.
     *
     * @param ServiceProviderInterface|string $provider
     *
     * @return self
     */
    
public function addServiceProvider($provider) : self
    
{
        
$this->providers->add($provider);

        return 
$this;
    }

    
/**
     * {@inheritdoc}
     */
    
public function get($idbool $new false)
    {
        if (
$this->definitions->has($id)) {
            
$resolved $this->definitions->resolve($id$new);
            return 
$this->inflectors->inflect($resolved);
        }

        if (
$this->definitions->hasTag($id)) {
            
$arrayOf $this->definitions->resolveTagged($id$new);

            
array_walk($arrayOf, function (&$resolved) {
                
$resolved $this->inflectors->inflect($resolved);
            });

            return 
$arrayOf;
        }

        if (
$this->providers->provides($id)) {
            
$this->providers->register($id);

            if (!
$this->definitions->has($id) && !$this->definitions->hasTag($id)) {
                throw new 
ContainerException(sprintf('Service provider lied about providing (%s) service'$id));
            }

            return 
$this->get($id$new);
        }

        foreach (
$this->delegates as $delegate) {
            if (
$delegate->has($id)) {
                
$resolved $delegate->get($id);
                return 
$this->inflectors->inflect($resolved);
            }
        }

        throw new 
NotFoundException(sprintf('Alias (%s) is not being managed by the container or delegates'$id));
    }

    
/**
     * {@inheritdoc}
     */
    
public function has($id) : bool
    
{
        if (
$this->definitions->has($id)) {
            return 
true;
        }

        if (
$this->definitions->hasTag($id)) {
            return 
true;
        }

        if (
$this->providers->provides($id)) {
            return 
true;
        }

        foreach (
$this->delegates as $delegate) {
            if (
$delegate->has($id)) {
                return 
true;
            }
        }

        return 
false;
    }

    
/**
     * Allows for manipulation of specific types on resolution.
     *
     * @param string        $type
     * @param callable|null $callback
     *
     * @return InflectorInterface
     */
    
public function inflector(string $type, ?callable $callback null) : InflectorInterface
    
{
        return 
$this->inflectors->add($type$callback);
    }

    
/**
     * Delegate a backup container to be checked for services if it
     * cannot be resolved via this container.
     *
     * @param ContainerInterface $container
     *
     * @return self
     */
    
public function delegate(ContainerInterface $container) : self
    
{
        
$this->delegates[] = $container;

        if (
$container instanceof ContainerAwareInterface) {
            
$container->setLeagueContainer($this);
        }

        return 
$this;
    }
}