-
-
Notifications
You must be signed in to change notification settings - Fork 874
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(serializer): hal format detecting circular reference
- Loading branch information
1 parent
0b6ea3b
commit d3efc4a
Showing
5 changed files
with
135 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
<?php | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue4358; | ||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* 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\ApiResource\Issue4358; | ||
|
||
use ApiPlatform\Metadata\ApiProperty; | ||
use ApiPlatform\Metadata\Get; | ||
|
@@ -19,33 +29,36 @@ final class ResourceA | |
|
||
#[ApiProperty(readableLink: true)] | ||
#[Groups(['ResourceA:read', 'ResourceB:read'])] | ||
#[MaxDepth(3)] | ||
#[MaxDepth(6)] | ||
public ResourceB $b; | ||
|
||
public function __construct(?ResourceB $b = null) | ||
{ | ||
if ($b !== null) { | ||
if (null !== $b) { | ||
$this->b = $b; | ||
} | ||
} | ||
|
||
public static function provide(): ResourceA | ||
public static function provide(): self | ||
{ | ||
return self::provideWithResource(); | ||
} | ||
|
||
public static function provideWithResource(?ResourceB $b = null): ResourceA { | ||
if(!isset(self::$resourceA)) { | ||
self::$resourceA = new ResourceA($b); | ||
public static function provideWithResource(?ResourceB $b = null): self | ||
{ | ||
if (!isset(self::$resourceA)) { | ||
self::$resourceA = new self($b); | ||
|
||
if(ResourceB::getInstance() === null) { | ||
if (null === ResourceB::getInstance()) { | ||
self::$resourceA->b = ResourceB::provideWithResource(self::$resourceA); | ||
} | ||
} | ||
|
||
return self::$resourceA; | ||
} | ||
|
||
public static function getInstance(): ?ResourceA { | ||
public static function getInstance(): ?self | ||
{ | ||
return self::$resourceA; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* 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\ApiResource\Issue4358; | ||
|
||
use ApiPlatform\Metadata\ApiProperty; | ||
|
@@ -18,36 +29,36 @@ final class ResourceB | |
|
||
#[ApiProperty(readableLink: true)] | ||
#[Groups(['ResourceA:read', 'ResourceB:read'])] | ||
#[MaxDepth(3)] | ||
#[MaxDepth(6)] | ||
public ResourceA $a; | ||
|
||
public function __construct(?ResourceA $a = null) | ||
{ | ||
if ($a !== null) { | ||
if (null !== $a) { | ||
$this->a = $a; | ||
} | ||
} | ||
|
||
public static function provide(): ResourceB | ||
public static function provide(): self | ||
{ | ||
return self::provideWithResource(); | ||
} | ||
|
||
public static function provideWithResource(?ResourceA $a = null): ResourceB | ||
public static function provideWithResource(?ResourceA $a = null): self | ||
{ | ||
if(!isset(self::$resourceB)) { | ||
self::$resourceB = new ResourceB($a); | ||
if (!isset(self::$resourceB)) { | ||
self::$resourceB = new self($a); | ||
|
||
if(ResourceA::getInstance() === null) { | ||
if (null === ResourceA::getInstance()) { | ||
self::$resourceB->a = ResourceA::provideWithResource(self::$resourceB); | ||
} | ||
} | ||
|
||
return self::$resourceB; | ||
} | ||
|
||
public static function getInstance(): ?ResourceB | ||
public static function getInstance(): ?self | ||
{ | ||
return self::$resourceB; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* 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\Functional; | ||
|
||
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; | ||
|
@@ -11,11 +22,11 @@ class HALCircularReference extends ApiTestCase | |
{ | ||
use SetupClassResourcesTrait; | ||
|
||
public function testIssue4358() | ||
public function testIssue4358(): void | ||
{ | ||
$r1 = self::createClient()->request('GET', '/resource_a', ['headers' => ['Accept' => 'application/hal+json']]); | ||
$this->assertResponseIsSuccessful(); | ||
echo $r1->getContent(); | ||
self::assertResponseIsSuccessful(); | ||
self::assertEquals('{"_links":{"self":{"href":"\/resource_a"},"b":{"href":"\/resource_b"}},"_embedded":{"b":{"_links":{"self":{"href":"\/resource_b"},"a":{"href":"\/resource_a"}},"_embedded":{"a":{"_links":{"self":{"href":"\/resource_a"}}}}}}}', $r1->getContent()); | ||
} | ||
|
||
public static function getResources(): array | ||
|