Skip to content

Commit 8c8ab19

Browse files
committed
feat: 🎸 enable to skip autoconfiguration with new SkipAutoconfigure attribute
1 parent 15ea6d8 commit 8c8ab19

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

‎src/Laravel/ApiPlatformDeferredProvider.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
use ApiPlatform\Laravel\State\ValidateProvider;
5252
use ApiPlatform\Metadata\IdentifiersExtractorInterface;
5353
use ApiPlatform\Metadata\InflectorInterface;
54+
use ApiPlatform\Metadata\Laravel\SkipAutoconfigure;
5455
use ApiPlatform\Metadata\Operation\PathSegmentNameGeneratorInterface;
5556
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
5657
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
@@ -102,6 +103,15 @@ public function register(): void
102103
$directory = app_path();
103104
$classes = ReflectionClassRecursiveIterator::getReflectionClassesFromDirectories([$directory], '(?!.*Test\.php$)');
104105

106+
foreach ($classes as $className => $refl) {
107+
foreach ($refl->getAttributes() as $attribute) {
108+
if (SkipAutoconfigure::class === $attribute->getName()) {
109+
unset($classes[$className]);
110+
break;
111+
}
112+
}
113+
}
114+
105115
$this->autoconfigure($classes, QueryExtensionInterface::class, [FilterQueryExtension::class]);
106116
$this->app->singleton(ItemProvider::class, function (Application $app) {
107117
$tagged = iterator_to_array($app->tagged(LinksHandlerInterface::class));
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Metadata\Laravel;
15+
16+
#[\Attribute(\Attribute::TARGET_CLASS)]
17+
class SkipAutoconfigure
18+
{
19+
}

0 commit comments

Comments
 (0)