1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the humbug/php-scoper package. |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2017 Théo FIDRY <[email protected]>, |
9
|
|
|
* Pádraic Brady <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Humbug\PhpScoper; |
16
|
|
|
|
17
|
|
|
use Humbug\PhpScoper\Configuration\ConfigurationFactory; |
18
|
|
|
use Humbug\PhpScoper\Configuration\RegexChecker; |
19
|
|
|
use Humbug\PhpScoper\Configuration\SymbolsConfigurationFactory; |
20
|
|
|
use Humbug\PhpScoper\PhpParser\Printer\Printer; |
21
|
|
|
use Humbug\PhpScoper\PhpParser\Printer\StandardPrinter; |
22
|
|
|
use Humbug\PhpScoper\Scoper\ScoperFactory; |
23
|
|
|
use Humbug\PhpScoper\Symbol\EnrichedReflectorFactory; |
24
|
|
|
use Humbug\PhpScoper\Symbol\Reflector; |
25
|
|
|
use PhpParser\Lexer; |
26
|
|
|
use PhpParser\Parser; |
27
|
|
|
use PhpParser\ParserFactory; |
28
|
|
|
use PhpParser\PrettyPrinter\Standard; |
29
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
30
|
|
|
|
31
|
|
|
final class Container |
32
|
|
|
{ |
33
|
|
|
private Filesystem $filesystem; |
34
|
|
|
private ConfigurationFactory $configFactory; |
35
|
|
|
private Parser $parser; |
36
|
|
|
private Reflector $reflector; |
37
|
|
|
private ScoperFactory $scoperFactory; |
38
|
|
|
private EnrichedReflectorFactory $enrichedReflectorFactory; |
39
|
|
|
private Printer $printer; |
40
|
|
|
|
41
|
|
|
public function getFileSystem(): Filesystem |
42
|
|
|
{ |
43
|
|
|
if (!isset($this->filesystem)) { |
44
|
|
|
$this->filesystem = new Filesystem(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->filesystem; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getConfigurationFactory(): ConfigurationFactory |
51
|
|
|
{ |
52
|
|
|
if (!isset($this->configFactory)) { |
53
|
|
|
$this->configFactory = new ConfigurationFactory( |
54
|
|
|
$this->getFileSystem(), |
55
|
|
|
new SymbolsConfigurationFactory( |
56
|
|
|
new RegexChecker(), |
57
|
|
|
), |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $this->configFactory; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getScoperFactory(): ScoperFactory |
65
|
|
|
{ |
66
|
|
|
if (!isset($this->scoperFactory)) { |
67
|
|
|
$this->scoperFactory = new ScoperFactory( |
68
|
|
|
$this->getParser(), |
69
|
|
|
$this->getEnrichedReflectorFactory(), |
70
|
|
|
$this->getPrinter(), |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this->scoperFactory; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getParser(): Parser |
78
|
|
|
{ |
79
|
|
|
if (!isset($this->parser)) { |
80
|
|
|
$this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new Lexer()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $this->parser; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getReflector(): Reflector |
87
|
|
|
{ |
88
|
|
|
if (!isset($this->reflector)) { |
89
|
|
|
$this->reflector = Reflector::createWithPhpStormStubs(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $this->reflector; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getEnrichedReflectorFactory(): EnrichedReflectorFactory |
96
|
|
|
{ |
97
|
|
|
if (!isset($this->enrichedReflectorFactory)) { |
98
|
|
|
$this->enrichedReflectorFactory = new EnrichedReflectorFactory( |
99
|
|
|
$this->getReflector(), |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $this->enrichedReflectorFactory; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getPrinter(): Printer |
107
|
|
|
{ |
108
|
|
|
if (!isset($this->printer)) { |
109
|
|
|
$this->printer = new StandardPrinter( |
110
|
|
|
new Standard(), |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $this->printer; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|