1717use Humbug \PhpScoper \Configuration \ConfigurationFactory ;
1818use Humbug \PhpScoper \Configuration \RegexChecker ;
1919use Humbug \PhpScoper \Configuration \SymbolsConfigurationFactory ;
20+ use Humbug \PhpScoper \PhpParser \Parser \ParserFactory ;
21+ use Humbug \PhpScoper \PhpParser \Parser \StandardParserFactory ;
2022use Humbug \PhpScoper \PhpParser \Printer \Printer ;
23+ use Humbug \PhpScoper \PhpParser \Printer \PrinterFactory ;
2124use Humbug \PhpScoper \PhpParser \Printer \StandardPrinter ;
22- use Humbug \PhpScoper \Scoper \ScoperFactory ;
25+ use Humbug \PhpScoper \PhpParser \Printer \StandardPrinterFactory ;
26+ use Humbug \PhpScoper \Scoper \Factory \ScoperFactory ;
27+ use Humbug \PhpScoper \Scoper \Factory \StandardScoperFactory ;
2328use Humbug \PhpScoper \Symbol \EnrichedReflectorFactory ;
2429use Humbug \PhpScoper \Symbol \Reflector ;
25- use PhpParser \Lexer ;
26- use PhpParser \Lexer \Emulative ;
2730use PhpParser \Parser ;
28- use PhpParser \Parser \Php7 ;
29- use PhpParser \Parser \Php8 ;
3031use PhpParser \PhpVersion ;
3132use PhpParser \PrettyPrinter \Standard ;
3233use Symfony \Component \Filesystem \Filesystem ;
@@ -36,12 +37,14 @@ final class Container
3637{
3738 private Filesystem $ filesystem ;
3839 private ConfigurationFactory $ configFactory ;
40+ private ParserFactory $ parserFactory ;
3941 private Parser $ parser ;
4042 private ?PhpVersion $ parserPhpVersion = null ;
4143 private ?PhpVersion $ printerPhpVersion = null ;
4244 private Reflector $ reflector ;
4345 private ScoperFactory $ scoperFactory ;
4446 private EnrichedReflectorFactory $ enrichedReflectorFactory ;
47+ private PrinterFactory $ printerFactory ;
4548 private Printer $ printer ;
4649
4750 public function getFileSystem (): Filesystem
@@ -67,39 +70,41 @@ public function getConfigurationFactory(): ConfigurationFactory
6770 return $ this ->configFactory ;
6871 }
6972
70- public function getScoperFactory (? PhpVersion $ phpVersion = null ): ScoperFactory
73+ public function getScoperFactory (): ScoperFactory
7174 {
7275 if (!isset ($ this ->scoperFactory )) {
73- $ this ->scoperFactory = new ScoperFactory (
74- $ this ->getParser ($ phpVersion ),
76+ $ this ->scoperFactory = new StandardScoperFactory (
7577 $ this ->getEnrichedReflectorFactory (),
76- $ this ->getPrinter (),
78+ $ this ->getParserFactory (),
79+ $ this ->getPrinterFactory (),
7780 );
7881 }
7982
8083 return $ this ->scoperFactory ;
8184 }
8285
86+ /**
87+ * @deprecated Use ::getParserFactory() instead.
88+ */
8389 public function getParser (?PhpVersion $ phpVersion = null ): Parser
8490 {
8591 if (!isset ($ this ->parser )) {
8692 $ this ->parserPhpVersion = $ phpVersion ;
87- $ this ->parser = $ this ->createParser ($ phpVersion );
93+ $ this ->parser = $ this ->getParserFactory ()-> createParser ($ phpVersion );
8894 }
8995
9096 self ::checkSamePhpVersion ($ this ->parserPhpVersion , $ phpVersion );
9197
9298 return $ this ->parser ;
9399 }
94100
95- private function createParser (? PhpVersion $ phpVersion ): Parser
101+ public function getParserFactory ( ): ParserFactory
96102 {
97- $ version = $ phpVersion ?? PhpVersion::getHostVersion ();
98- $ lexer = $ version ->isHostVersion () ? new Lexer () : new Emulative ($ version );
103+ if (!isset ($ this ->parserFactory )) {
104+ $ this ->parserFactory = new StandardParserFactory ();
105+ }
99106
100- return $ version ->id >= 80_000
101- ? new Php8 ($ lexer , $ version )
102- : new Php7 ($ lexer , $ version );
107+ return $ this ->parserFactory ;
103108 }
104109
105110 public function getReflector (): Reflector
@@ -122,6 +127,9 @@ public function getEnrichedReflectorFactory(): EnrichedReflectorFactory
122127 return $ this ->enrichedReflectorFactory ;
123128 }
124129
130+ /**
131+ * @deprecated use ::getPrinterFactory() instead.
132+ */
125133 public function getPrinter (?PhpVersion $ phpVersion = null ): Printer
126134 {
127135 if (!isset ($ this ->printer )) {
@@ -138,6 +146,15 @@ public function getPrinter(?PhpVersion $phpVersion = null): Printer
138146 return $ this ->printer ;
139147 }
140148
149+ public function getPrinterFactory (): PrinterFactory
150+ {
151+ if (!isset ($ this ->printerFactory )) {
152+ $ this ->printerFactory = new StandardPrinterFactory ();
153+ }
154+
155+ return $ this ->printerFactory ;
156+ }
157+
141158 private static function checkSamePhpVersion (
142159 ?PhpVersion $ versionUsed ,
143160 ?PhpVersion $ versionRequest ,
0 commit comments