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