From 2392bf09c04e13f7897c6ce21221d4c90a2abf45 Mon Sep 17 00:00:00 2001 From: denise Date: Fri, 6 Sep 2024 19:00:27 +0800 Subject: [PATCH 1/2] add exclude paths option --- src/AopKernel.php | 7 +++++++ src/Core/AutoloadInterceptor/ClassLoader.php | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/AopKernel.php b/src/AopKernel.php index 677120a..1a79ea5 100644 --- a/src/AopKernel.php +++ b/src/AopKernel.php @@ -57,6 +57,13 @@ abstract class AopKernel extends CodeTransformerKernel */ protected ?string $cacheDir = null; + /** + * The exclude paths. Paths/directories in this array will be excluded + * + * @var array + */ + protected array $excludePaths = []; + // endregion /** diff --git a/src/Core/AutoloadInterceptor/ClassLoader.php b/src/Core/AutoloadInterceptor/ClassLoader.php index df66749..a114026 100644 --- a/src/Core/AutoloadInterceptor/ClassLoader.php +++ b/src/Core/AutoloadInterceptor/ClassLoader.php @@ -58,6 +58,11 @@ public function findFile($namespacedClass): false|string $filePath = Path::resolve($filePath); + foreach ($this->options->getExcludePaths() as $path) { + if (str_starts_with($filePath, $path)) { + return $filePath; + } + } // Query cache state $cacheState = $this->cacheStateManager->queryCacheState($filePath); From 4c87494dd4fb8a580ada13066002c4358434c253 Mon Sep 17 00:00:00 2001 From: denise Date: Fri, 6 Sep 2024 22:51:18 +0800 Subject: [PATCH 2/2] accept relative path --- src/Core/AutoloadInterceptor/ClassLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/AutoloadInterceptor/ClassLoader.php b/src/Core/AutoloadInterceptor/ClassLoader.php index a114026..7b2ccbf 100644 --- a/src/Core/AutoloadInterceptor/ClassLoader.php +++ b/src/Core/AutoloadInterceptor/ClassLoader.php @@ -59,7 +59,7 @@ public function findFile($namespacedClass): false|string $filePath = Path::resolve($filePath); foreach ($this->options->getExcludePaths() as $path) { - if (str_starts_with($filePath, $path)) { + if (str_starts_with($filePath, Path::resolve($path))) { return $filePath; } }