|
6 | 6 | use DI\Attribute\Inject;
|
7 | 7 | use Okapi\CodeTransformer\Core\AutoloadInterceptor;
|
8 | 8 | use Okapi\CodeTransformer\Core\Cache\CacheStateManager;
|
| 9 | +use Okapi\CodeTransformer\Core\CachedStreamFilter; |
9 | 10 | use Okapi\CodeTransformer\Core\Matcher\TransformerMatcher;
|
10 | 11 | use Okapi\CodeTransformer\Core\Options;
|
11 | 12 | use Okapi\CodeTransformer\Core\Options\Environment;
|
@@ -120,26 +121,50 @@ public function findFile($namespacedClass): false|string
|
120 | 121 | && $cacheState
|
121 | 122 | ) {
|
122 | 123 | // Use the cached file if transformations have been applied
|
| 124 | + if ($cacheFilePath = $cacheState->getFilePath()) { |
| 125 | + $this->classContainer->addClassContext( |
| 126 | + $filePath, |
| 127 | + $namespacedClass, |
| 128 | + $cacheFilePath, |
| 129 | + ); |
| 130 | + |
| 131 | + // For cached files, the debugger will have trouble finding the |
| 132 | + // original file, that's why we rewrite the file path with a PHP |
| 133 | + // stream filter |
| 134 | + /** @see CachedStreamFilter::filter() */ |
| 135 | + return $this->filterInjector->rewriteCached($filePath); |
| 136 | + } |
| 137 | + |
123 | 138 | // Or return the original file if no transformations have been applied
|
124 |
| - return $cacheState->getFilePath() ?? $filePath; |
| 139 | + return $filePath; |
125 | 140 | }
|
126 | 141 |
|
127 | 142 | // In development mode, check if the cache is fresh
|
128 | 143 | elseif ($this->options->getEnvironment() === Environment::DEVELOPMENT
|
129 | 144 | && $cacheState
|
130 | 145 | && $cacheState->isFresh()
|
131 | 146 | ) {
|
132 |
| - return $cacheState->getFilePath() ?? $filePath; |
| 147 | + if ($cacheFilePath = $cacheState->getFilePath()) { |
| 148 | + $this->classContainer->addClassContext( |
| 149 | + $filePath, |
| 150 | + $namespacedClass, |
| 151 | + $cacheFilePath, |
| 152 | + ); |
| 153 | + |
| 154 | + return $this->filterInjector->rewriteCached($filePath); |
| 155 | + } |
| 156 | + |
| 157 | + return $filePath; |
133 | 158 | }
|
134 | 159 |
|
135 | 160 |
|
136 | 161 | // Check if the class should be transformed
|
137 |
| - if (!$this->transformerMatcher->match($namespacedClass, $filePath)) { |
| 162 | + if (!$this->transformerMatcher->matchAndStore($namespacedClass, $filePath)) { |
138 | 163 | return $filePath;
|
139 | 164 | }
|
140 | 165 |
|
141 | 166 | // Add the class to store the file path
|
142 |
| - $this->classContainer->addNamespacedClassPath($filePath, $namespacedClass); |
| 167 | + $this->classContainer->addClassContext($filePath, $namespacedClass); |
143 | 168 |
|
144 | 169 | // Replace the file path with a PHP stream filter
|
145 | 170 | /** @see StreamFilter::filter() */
|
|
0 commit comments