1313use Composer \Plugin \PluginInterface ;
1414use Composer \Script \Event ;
1515use Composer \Script \ScriptEvents ;
16+ use PhpParser \Lexer \Emulative ;
1617use PhpParser \ParserFactory ;
1718use PhpParser \PrettyPrinter \Standard ;
19+ use Psr \Log \LoggerInterface ;
1820use ReflectionClass ;
1921use Rx \Observable ;
2022use Throwable ;
@@ -75,6 +77,7 @@ public static function generateProxies(Event $event): void
7577 $ start = microtime (true );
7678 $ io = $ event ->getIO ();
7779 $ composer = $ event ->getComposer ();
80+ $ rootPath = self ::locateRootPackageInstallPath ($ composer ->getConfig (), $ composer ->getPackage ());
7881
7982 if (! function_exists ('React\Promise\Resolve ' )) {
8083 /** @psalm-suppress UnresolvableInclude */
@@ -124,7 +127,7 @@ public static function generateProxies(Event $event): void
124127 $ io ->write ('<info>react-parallel/object-proxy:</info> Locating interfaces ' );
125128
126129 $ installPath = self ::locateRootPackageInstallPath ($ composer ->getConfig (), $ composer ->getPackage ()) . '/src/Generated/ ' ;
127- $ proxies = self ::getProxies ($ composer , $ io );
130+ $ proxies = self ::getProxies ($ composer , $ io, $ rootPath );
128131
129132 $ io ->write ('<info>react-parallel/object-proxy:</info> Found ' . count ($ proxies ) . ' interface(s) and generated a proxy for each of them ' );
130133
@@ -141,7 +144,7 @@ public static function generateProxies(Event $event): void
141144 "['%s'] " ,
142145 '%s ' ,
143146 file_get_contents (
144- self :: locateRootPackageInstallPath ( $ composer -> getConfig (), $ composer -> getPackage ()) . '/etc/ProxyList.php '
147+ $ rootPath . '/etc/ProxyList.php '
145148 )
146149 ),
147150 var_export ($ interfaces , TRUE_ )
@@ -174,9 +177,9 @@ private static function locateRootPackageInstallPath(
174177 /**
175178 * @return array<InterfaceProxier>
176179 */
177- private static function getProxies (Composer $ composer , IOInterface $ io ): array
180+ private static function getProxies (Composer $ composer , IOInterface $ io, string $ rootPath ): array
178181 {
179- $ phpParser = $ parser = (new ParserFactory ())->create (ParserFactory::PREFER_PHP7 );
182+ $ phpParser = $ parser = (new ParserFactory ())->create (ParserFactory::PREFER_PHP7 , new Emulative ([ ' comments ' => true ]) );
180183
181184 $ result = [];
182185 $ packages = $ composer ->getRepositoryManager ()->getLocalRepository ()->getCanonicalPackages ();
@@ -189,14 +192,22 @@ private static function getProxies(Composer $composer, IOInterface $io): array
189192 static fn (array $ interfaces ): Observable => observableFromArray (array_unique (array_values ($ interfaces )))
190193 )->map (
191194 /** @phpstan-ignore-next-line */
192- static function (string $ interface ) use ($ io , $ phpParser ): ?array {
195+ static function (string $ interface ) use ($ io , $ phpParser, $ rootPath ): ?array {
193196 $ io ->write (sprintf ('<info>react-parallel/object-proxy:</info> Creating proxy for %s ' , $ interface ));
194197
195198 /**
196199 * @psalm-suppress ArgumentTypeCoercion
197200 * @phpstan-ignore-next-line
198201 */
199- return $ phpParser ->parse (file_get_contents ((new ReflectionClass ($ interface ))->getFileName ()));
202+ $ fileName = (new ReflectionClass ($ interface ))->getFileName ();
203+ if ($ interface === LoggerInterface::class) {
204+ $ fileName = $ rootPath . '/vendor/psr/log/Psr/Log/LoggerInterface.php ' ;
205+ }
206+
207+ /**
208+ * @phpstan-ignore-next-line
209+ */
210+ return $ phpParser ->parse (file_get_contents ($ fileName ));
200211 }
201212 )->filter (
202213 static fn (?array $ ast ): bool => is_array ($ ast )
0 commit comments