Skip to content

Commit 5106027

Browse files
authored
Add exclude paths option
2 parents dd338c9 + dce6412 commit 5106027

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

src/CodeTransformerKernel.php

+8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ public function __construct() {}
7373
*/
7474
protected ?string $cacheDir = null;
7575

76+
/**
77+
* The exclude paths. Paths/directories in this array will be excluded
78+
*
79+
* @var array
80+
*/
81+
protected array $excludePaths = [];
82+
7683
/**
7784
* The cache file mode.
7885
* <br><b>Default:</b> 0777 & ~{@link umask()}<br>
@@ -187,6 +194,7 @@ protected function preInit(): void
187194
cacheFileMode: $this->cacheFileMode,
188195
debug: $this->debug,
189196
environment: $this->environment,
197+
excludePaths: $this->excludePaths,
190198
);
191199

192200
// Add the transformers

src/Core/AutoloadInterceptor/ClassLoader.php

+5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public function findFile($namespacedClass): false|string
107107

108108
$filePath = Path::resolve($filePath);
109109

110+
foreach ($this->options->getExcludePaths() as $path) {
111+
if (str_starts_with($filePath, Path::resolve($path))) {
112+
return $filePath;
113+
}
114+
}
110115

111116
// Query cache state
112117
$cacheState = $this->cacheStateManager->queryCacheState($filePath);

src/Core/Options.php

+17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class Options implements ServiceInterface
3232
*/
3333
private string $cacheDir;
3434

35+
/**
36+
* The exclude paths.
37+
*
38+
* @var array
39+
*/
40+
private array $excludePaths;
41+
3542
/**
3643
* The cache file mode.
3744
*
@@ -79,6 +86,7 @@ public function setOptions(
7986
?int $cacheFileMode,
8087
bool $debug,
8188
Environment $environment,
89+
array $excludePaths = [],
8290
): void {
8391
$composerRef = new ReflectionClass(ClassLoader::class);
8492
$composerDir = $composerRef->getFileName();
@@ -89,6 +97,7 @@ public function setOptions(
8997
$this->cacheFileMode = $cacheFileMode ?? (0777 & ~umask());
9098
$this->debug = $debug;
9199
$this->environment = $environment;
100+
$this->excludePaths = $excludePaths;
92101
}
93102

94103
// endregion
@@ -121,6 +130,14 @@ public function getCacheDir(): string
121130
return $this->cacheDir;
122131
}
123132

133+
/**
134+
* Get the exclude paths.
135+
*/
136+
public function getExcludePaths(): array
137+
{
138+
return $this->excludePaths;
139+
}
140+
124141
/**
125142
* Get the cache file mode.
126143
*/

tests/Functional/Transformer/SyntaxErrorInTransformedClass/Transformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function transform(Code $code): void
1919
$refClass = $code->getReflectionClass();
2020
assert($refClass->getName() === Target::class);
2121

22-
$className = $code->getClassName();
22+
$className = $code->getNewSource();
2323
assert($className === 'SyntaxErrorClass');
2424
}
2525
}

0 commit comments

Comments
 (0)