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\Scoper\ScoperFactory; |
21
|
|
|
use Humbug\PhpScoper\Symbol\EnrichedReflectorFactory; |
22
|
|
|
use Humbug\PhpScoper\Symbol\Reflector; |
23
|
|
|
use PhpParser\Lexer; |
24
|
|
|
use PhpParser\Parser; |
25
|
|
|
use PhpParser\ParserFactory; |
26
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
27
|
|
|
|
28
|
|
|
final class Container |
29
|
|
|
{ |
30
|
|
|
private Filesystem $filesystem; |
31
|
|
|
private ConfigurationFactory $configFactory; |
32
|
|
|
private Parser $parser; |
33
|
|
|
private Reflector $reflector; |
34
|
|
|
private ScoperFactory $scoperFactory; |
35
|
|
|
private EnrichedReflectorFactory $enrichedReflectorFactory; |
36
|
|
|
|
37
|
|
|
public function getFileSystem(): Filesystem |
38
|
|
|
{ |
39
|
|
|
if (!isset($this->filesystem)) { |
40
|
|
|
$this->filesystem = new Filesystem(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $this->filesystem; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getConfigurationFactory(): ConfigurationFactory |
47
|
|
|
{ |
48
|
|
|
if (!isset($this->configFactory)) { |
49
|
|
|
$this->configFactory = new ConfigurationFactory( |
50
|
|
|
$this->getFileSystem(), |
51
|
|
|
new SymbolsConfigurationFactory( |
52
|
|
|
new RegexChecker(), |
53
|
|
|
), |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this->configFactory; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getScoperFactory(): ScoperFactory |
61
|
|
|
{ |
62
|
|
|
if (!isset($this->scoperFactory)) { |
63
|
|
|
$this->scoperFactory = new ScoperFactory( |
64
|
|
|
$this->getParser(), |
65
|
|
|
$this->getEnrichedReflectorFactory(), |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $this->scoperFactory; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getParser(): Parser |
73
|
|
|
{ |
74
|
|
|
if (!isset($this->parser)) { |
75
|
|
|
$this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new Lexer()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $this->parser; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getReflector(): Reflector |
82
|
|
|
{ |
83
|
|
|
if (!isset($this->reflector)) { |
84
|
|
|
$this->reflector = Reflector::createWithPhpStormStubs(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->reflector; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getEnrichedReflectorFactory(): EnrichedReflectorFactory |
91
|
|
|
{ |
92
|
|
|
if (!isset($this->enrichedReflectorFactory)) { |
93
|
|
|
$this->enrichedReflectorFactory = new EnrichedReflectorFactory( |
94
|
|
|
$this->getReflector(), |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $this->enrichedReflectorFactory; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|