From 8c8ab194707a58c58b3d0b1857045f7fa91d783a Mon Sep 17 00:00:00 2001 From: Takashi Kanemoto Date: Sat, 18 Oct 2025 18:24:32 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20enable=20to=20skip=20aut?= =?UTF-8?q?oconfiguration=20with=20new=20`SkipAutoconfigure`=20attribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Laravel/ApiPlatformDeferredProvider.php | 10 ++++++++++ src/Metadata/Laravel/SkipAutoconfigure.php | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/Metadata/Laravel/SkipAutoconfigure.php diff --git a/src/Laravel/ApiPlatformDeferredProvider.php b/src/Laravel/ApiPlatformDeferredProvider.php index 227e2f9c68..1cced63494 100644 --- a/src/Laravel/ApiPlatformDeferredProvider.php +++ b/src/Laravel/ApiPlatformDeferredProvider.php @@ -51,6 +51,7 @@ use ApiPlatform\Laravel\State\ValidateProvider; use ApiPlatform\Metadata\IdentifiersExtractorInterface; use ApiPlatform\Metadata\InflectorInterface; +use ApiPlatform\Metadata\Laravel\SkipAutoconfigure; use ApiPlatform\Metadata\Operation\PathSegmentNameGeneratorInterface; use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; @@ -102,6 +103,15 @@ public function register(): void $directory = app_path(); $classes = ReflectionClassRecursiveIterator::getReflectionClassesFromDirectories([$directory], '(?!.*Test\.php$)'); + foreach ($classes as $className => $refl) { + foreach ($refl->getAttributes() as $attribute) { + if (SkipAutoconfigure::class === $attribute->getName()) { + unset($classes[$className]); + break; + } + } + } + $this->autoconfigure($classes, QueryExtensionInterface::class, [FilterQueryExtension::class]); $this->app->singleton(ItemProvider::class, function (Application $app) { $tagged = iterator_to_array($app->tagged(LinksHandlerInterface::class)); diff --git a/src/Metadata/Laravel/SkipAutoconfigure.php b/src/Metadata/Laravel/SkipAutoconfigure.php new file mode 100644 index 0000000000..e16169b4d6 --- /dev/null +++ b/src/Metadata/Laravel/SkipAutoconfigure.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Metadata\Laravel; + +#[\Attribute(\Attribute::TARGET_CLASS)] +class SkipAutoconfigure +{ +}