1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Container\Bridges; |
4
|
|
|
|
5
|
|
|
use League\Container\Container as Container; |
6
|
|
|
use LogicException; |
7
|
|
|
use Nip\Container\Traits\ContainerArrayAccessTrait; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class LeagueContainer |
11
|
|
|
* @package Nip\Container\Bridges |
12
|
|
|
*/ |
13
|
|
|
abstract class LeagueContainer extends Container implements BridgeInterface |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The registered type aliases. |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
protected $aliases = []; |
22
|
|
|
|
23
|
|
|
use ContainerArrayAccessTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritdoc |
27
|
|
|
*/ |
28
|
1 |
|
public function set($alias, $concrete = null, $share = false) |
29
|
|
|
{ |
30
|
1 |
|
return $this->add($alias, $concrete, $share); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc |
35
|
|
|
*/ |
36
|
|
|
public function remove($alias) |
37
|
|
|
{ |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Determine if a given string is an alias. |
42
|
|
|
* |
43
|
|
|
* @param string $name |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
|
|
public function isAlias($name) |
47
|
|
|
{ |
48
|
|
|
return isset($this->aliases[$name]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Alias a type to a different name. |
53
|
|
|
* |
54
|
|
|
* @param string $abstract |
55
|
|
|
* @param string $alias |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
1 |
|
public function alias($abstract, $alias) |
59
|
|
|
{ |
60
|
1 |
|
$this->aliases[$alias] = $abstract; |
61
|
|
|
// $this->abstractAliases[$abstract][] = $alias; |
|
|
|
|
62
|
|
|
|
63
|
1 |
|
$this->share($alias, function () use ($abstract) { |
64
|
1 |
|
return $this->get($abstract); |
65
|
1 |
|
}); |
66
|
1 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the alias for an abstract if available. |
70
|
|
|
* |
71
|
|
|
* @param string $abstract |
72
|
|
|
* @return string |
73
|
|
|
* |
74
|
|
|
* @throws \LogicException |
75
|
|
|
*/ |
76
|
|
|
public function getAlias($abstract) |
77
|
|
|
{ |
78
|
|
|
if (!isset($this->aliases[$abstract])) { |
79
|
|
|
return $abstract; |
80
|
|
|
} |
81
|
|
|
if ($this->aliases[$abstract] === $abstract) { |
82
|
|
|
throw new LogicException("[{$abstract}] is aliased to itself."); |
83
|
|
|
} |
84
|
|
|
return $this->getAlias($this->aliases[$abstract]); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.