66use Okapi \Aop \Core \Matcher \AspectMatcher ;
77use Okapi \CodeTransformer \Core \AutoloadInterceptor ;
88use Okapi \CodeTransformer \Core \AutoloadInterceptor \ClassLoader as CodeTransformerClassLoader ;
9+ use Okapi \CodeTransformer \Core \CachedStreamFilter ;
910use Okapi \CodeTransformer \Core \Options \Environment ;
1011use Okapi \CodeTransformer \Core \StreamFilter ;
1112use Okapi \CodeTransformer \Core \StreamFilter \FilterInjector ;
@@ -71,26 +72,50 @@ public function findFile($namespacedClass): false|string
7172 && $ cacheState
7273 ) {
7374 // Use the cached file if aspects have been applied
75+ if ($ cacheFilePath = $ cacheState ->getFilePath ()) {
76+ $ this ->classContainer ->addClassContext (
77+ $ filePath ,
78+ $ namespacedClass ,
79+ $ cacheFilePath ,
80+ );
81+
82+ // For cached files, the debugger will have trouble finding the
83+ // original file, that's why we rewrite the file path with a PHP
84+ // stream filter
85+ /** @see CachedStreamFilter::filter() */
86+ return $ this ->filterInjector ->rewriteCached ($ filePath );
87+ }
88+
7489 // Or return the original file if no aspects have been applied
75- return $ cacheState -> getFilePath () ?? $ filePath ;
90+ return $ filePath ;
7691 }
7792
7893 // In development mode, check if the cache is fresh
7994 elseif ($ this ->options ->getEnvironment () === Environment::DEVELOPMENT
8095 && $ cacheState
8196 && $ cacheState ->isFresh ()
8297 ) {
83- return $ cacheState ->getFilePath () ?? $ filePath ;
98+ if ($ cacheFilePath = $ cacheState ->getFilePath ()) {
99+ $ this ->classContainer ->addClassContext (
100+ $ filePath ,
101+ $ namespacedClass ,
102+ $ cacheFilePath ,
103+ );
104+
105+ return $ this ->filterInjector ->rewriteCached ($ filePath );
106+ }
107+
108+ return $ filePath ;
84109 }
85110
86111
87112 // Match the aspects
88- $ matchedAspects = $ this ->aspectMatcher ->matchByClassLoader (
113+ $ matchedAspects = $ this ->aspectMatcher ->matchByClassLoaderAndStore (
89114 $ namespacedClass ,
90115 );
91116
92117 // Match the transformer
93- $ matchedTransformers = $ this ->transformerMatcher ->match (
118+ $ matchedTransformers = $ this ->transformerMatcher ->matchAndStore (
94119 $ namespacedClass ,
95120 $ filePath ,
96121 );
@@ -101,7 +126,7 @@ public function findFile($namespacedClass): false|string
101126 }
102127
103128 // Add the class to store the file path
104- $ this ->classContainer ->addNamespacedClassPath ($ filePath , $ namespacedClass );
129+ $ this ->classContainer ->addClassContext ($ filePath , $ namespacedClass );
105130
106131 // Replace the file path with a PHP stream filter
107132 /** @see StreamFilter::filter() */
0 commit comments