Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private function buildResourceOperations(array $attributes, string $resourceClas
$operationPriority = 0;

foreach ($attributes as $attribute) {
if (ApiResource::class === $attribute->getName()) {
if (is_a($attribute->getName(), ApiResource::class, true)) {
$resource = $this->getResourceWithDefaults($resourceClass, $shortName, $attribute->newInstance());
$operations = [];
foreach ($resource->getOperations() ?? new Operations() as $operation) {
Expand Down Expand Up @@ -165,7 +165,7 @@ private function buildResourceOperations(array $attributes, string $resourceClas
private function hasResourceAttributes(\ReflectionClass $reflectionClass): bool
{
foreach ($reflectionClass->getAttributes() as $attribute) {
if (ApiResource::class === $attribute->getName() || is_subclass_of($attribute->getName(), HttpOperation::class) || is_subclass_of($attribute->getName(), GraphQlOperation::class)) {
if (is_a($attribute->getName(), ApiResource::class, true) || is_subclass_of($attribute->getName(), HttpOperation::class) || is_subclass_of($attribute->getName(), GraphQlOperation::class)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function create(): ResourceNameCollection

private function isResource(\ReflectionClass $reflectionClass): bool
{
if ($reflectionClass->getAttributes(ApiResource::class)) {
if ($reflectionClass->getAttributes(ApiResource::class, \ReflectionAttribute::IS_INSTANCEOF)) {
return true;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/Fixtures/TestBundle/Attributes/RestfulApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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\Tests\Fixtures\TestBundle\Attributes;

use ApiPlatform\Metadata\ApiResource;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
class RestfulApi extends ApiResource
{
}
36 changes: 36 additions & 0 deletions tests/Fixtures/TestBundle/Entity/InstanceOfApiResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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\Tests\Fixtures\TestBundle\Entity;

use ApiPlatform\Tests\Fixtures\TestBundle\Attributes\RestfulApi;
use Doctrine\ORM\Mapping as ORM;

#[RestfulApi]
#[ORM\Entity]
class InstanceOfApiResource
{
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;

public function __construct()
{
}

public function getId()
{
return $this->id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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\Tests\Metadata\Resource\Factory;

use ApiPlatform\Metadata\Resource\Factory\AttributesResourceNameCollectionFactory;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\InstanceOfApiResource;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

/**
* @author Yoann Brieux <github@brieux.net>
*/
class AttributesResourceNameCollectionFactoryTest extends TestCase
{
use ProphecyTrait;

public function testCreateWithInstanceOfApiResource(): void
{
$attributesResourceNameCollectionFactory = new AttributesResourceNameCollectionFactory(paths: [__DIR__.'/../../../Fixtures/TestBundle/Entity/']);

$this->assertContains(InstanceOfApiResource::class, $attributesResourceNameCollectionFactory->create()->getIterator());
}
}