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 @@ -57,6 +57,10 @@ public function create(string $resourceClass, string $property, array $options =
break;
}

if ($options['api_allow_update'] ?? false) {
break;
}

$propertyMetadata = $propertyMetadata->withWritable(false);

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function create(string $resourceClass, string $property, array $options =
break;
}

if ($options['api_allow_update'] ?? false) {
break;
}

if ($doctrineClassMetadata instanceof ClassMetadata) {
$writable = $doctrineClassMetadata->isIdentifierNatural();
} else {
Expand Down
18 changes: 9 additions & 9 deletions src/GraphQl/Tests/Serializer/ItemNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public function testNormalize(): void

$propertyNameCollection = new PropertyNameCollection(['name']);
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
$propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn($propertyNameCollection);
$propertyNameCollectionFactoryProphecy->create(Dummy::class, Argument::type('array'))->willReturn($propertyNameCollection);

$propertyMetadata = (new ApiProperty())->withReadable(true);
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn($propertyMetadata);
$propertyMetadataFactoryProphecy->create(Dummy::class, 'name', Argument::type('array'))->willReturn($propertyMetadata);

$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
$iriConverterProphecy->getIriFromResource($dummy, UrlGeneratorInterface::ABS_URL, Argument::any(), Argument::type('array'))->willReturn('/dummies/1');
Expand Down Expand Up @@ -131,13 +131,13 @@ public function testNormalizeWithUnsafeCacheProperty(): void

$propertyNameCollection = new PropertyNameCollection(['title', 'ownerOnlyProperty']);
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
$propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, [])->willReturn($propertyNameCollection);
$propertyNameCollectionFactoryProphecy->create(SecuredDummy::class, Argument::type('array'))->willReturn($propertyNameCollection);

$unsecuredPropertyMetadata = (new ApiProperty())->withReadable(true);
$securedPropertyMetadata = (new ApiProperty())->withReadable(true)->withSecurity('object == null or object.getOwner() == user');
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', [])->willReturn($unsecuredPropertyMetadata);
$propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'ownerOnlyProperty', [])->willReturn($securedPropertyMetadata);
$propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'title', Argument::type('array'))->willReturn($unsecuredPropertyMetadata);
$propertyMetadataFactoryProphecy->create(SecuredDummy::class, 'ownerOnlyProperty', Argument::type('array'))->willReturn($securedPropertyMetadata);

$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
$iriConverterProphecy->getIriFromResource($securedDummyWithOwnerOnlyPropertyAllowed, UrlGeneratorInterface::ABS_URL, Argument::any(), Argument::type('array'))->willReturn('/dummies/1');
Expand Down Expand Up @@ -216,11 +216,11 @@ public function testNormalizeNoResolverData(): void

$propertyNameCollection = new PropertyNameCollection(['name']);
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
$propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn($propertyNameCollection);
$propertyNameCollectionFactoryProphecy->create(Dummy::class, Argument::type('array'))->willReturn($propertyNameCollection);

$propertyMetadata = (new ApiProperty())->withWritable(true)->withReadable(true);
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn($propertyMetadata);
$propertyMetadataFactoryProphecy->create(Dummy::class, 'name', Argument::type('array'))->willReturn($propertyMetadata);

$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
$iriConverterProphecy->getIriFromResource($dummy, UrlGeneratorInterface::ABS_URL, Argument::any(), Argument::type('array'))->willReturn('/dummies/1');
Expand Down Expand Up @@ -260,11 +260,11 @@ public function testDenormalize(): void

$propertyNameCollection = new PropertyNameCollection(['name']);
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
$propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn($propertyNameCollection)->shouldBeCalled();
$propertyNameCollectionFactoryProphecy->create(Dummy::class, Argument::type('array'))->willReturn($propertyNameCollection)->shouldBeCalled();

$propertyMetadata = (new ApiProperty())->withWritable(true)->withReadable(true);
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn($propertyMetadata)->shouldBeCalled();
$propertyMetadataFactoryProphecy->create(Dummy::class, 'name', Argument::type('array'))->willReturn($propertyMetadata)->shouldBeCalled();

$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);

Expand Down
3 changes: 3 additions & 0 deletions src/Hal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/composer.lock
/vendor
/.phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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\Hal\Tests\Fixtures\ApiResource\Issue5452;

interface ActivableInterface
{
}
34 changes: 34 additions & 0 deletions src/Hal/Tests/Fixtures/ApiResource/Issue5452/Author.php
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\Hal\Tests\Fixtures\ApiResource\Issue5452;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Tests\Fixtures\TestBundle\State\Issue5452\AuthorItemProvider;

#[ApiResource(
operations: [
new Get(uriTemplate: '/issue-5452/authors/{id}{._format}', provider: AuthorItemProvider::class),
]
)]
class Author implements ActivableInterface, TimestampableInterface
{
public function __construct(
#[ApiProperty(identifier: true)]
public readonly string|int $id,
public readonly string $name,
) {
}
}
38 changes: 38 additions & 0 deletions src/Hal/Tests/Fixtures/ApiResource/Issue5452/Book.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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\Hal\Tests\Fixtures\ApiResource\Issue5452;

use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Tests\Fixtures\TestBundle\State\Issue5452\BookCollectionProvider;

#[GetCollection(uriTemplate: '/issue-5452/books{._format}', provider: BookCollectionProvider::class)]
#[Post(uriTemplate: '/issue-5452/books{._format}')]
class Book
{
// union types
public string|int|null $number = null;

// simple types
public ?string $isbn = null;

// intersect types without specific typehint (throw an error: AbstractItemNormalizer line 872)
public ActivableInterface&TimestampableInterface $library;

/**
* @var Author
*/
// intersect types with PHPDoc
public ActivableInterface&TimestampableInterface $author;
}
34 changes: 34 additions & 0 deletions src/Hal/Tests/Fixtures/ApiResource/Issue5452/Library.php
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\Hal\Tests\Fixtures\ApiResource\Issue5452;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Tests\Fixtures\TestBundle\State\Issue5452\LibraryItemProvider;

#[ApiResource(
operations: [
new Get(uriTemplate: '/issue-5452/libraries/{id}{._format}', provider: LibraryItemProvider::class),
]
)]
class Library implements ActivableInterface, TimestampableInterface
{
public function __construct(
#[ApiProperty(identifier: true)]
public readonly string|int $id,
public readonly string $name,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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\Hal\Tests\Fixtures\ApiResource\Issue5452;

interface TimestampableInterface
{
}
41 changes: 41 additions & 0 deletions src/Hal/Tests/Fixtures/Dummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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\Hal\Tests\Fixtures;

class Dummy
{
public int $id;
private $relatedDummy;
private $name;

public function getName(): string
{
return $this->name;
}

public function setName(string $name): void
{
$this->name = $name;
}

public function getRelatedDummy(): RelatedDummy
{
return $this->relatedDummy;
}

public function setRelatedDummy(RelatedDummy $relatedDummy): void
{
$this->relatedDummy = $relatedDummy;
}
}
37 changes: 37 additions & 0 deletions src/Hal/Tests/Fixtures/MaxDepthDummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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\Hal\Tests\Fixtures;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;

/**
* @author Brian Fox <brian@brianfox.fr>
*/
#[ApiResource(normalizationContext: ['groups' => ['default'], 'enable_max_depth' => true], denormalizationContext: ['groups' => ['default'], 'enable_max_depth' => true], graphQlOperations: [])]
class MaxDepthDummy
{
#[Groups(['default'])]
public $id;

#[Groups(['default'])]
public $name;

#[ApiProperty(fetchEager: false)]
#[Groups(['default'])]
#[MaxDepth(1)]
public $child;
}
19 changes: 19 additions & 0 deletions src/Hal/Tests/Fixtures/RelatedDummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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\Hal\Tests\Fixtures;

class RelatedDummy
{
public int $id;
}
Loading
Loading