Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/Laravel/ApiPlatformDeferredProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ public function register(): void
),
$app->make('filters'),
$app->make(CamelCaseToSnakeCaseNameConverter::class),
$this->app->make(LoggerInterface::class)
$this->app->make(LoggerInterface::class),
$app->make(ResourceClassResolverInterface::class),
),
$app->make('filters')
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use ApiPlatform\Metadata\Util\ResourceClassInfoTrait;
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;
use ApiPlatform\Serializer\Filter\FilterInterface as SerializerFilterInterface;
Expand Down Expand Up @@ -55,7 +56,9 @@ public function __construct(
private readonly ?ContainerInterface $filterLocator = null,
private readonly ?NameConverterInterface $nameConverter = null,
private readonly ?LoggerInterface $logger = null,
?ResourceClassResolverInterface $resourceClassResolver = null,
) {
$this->resourceClassResolver = $resourceClassResolver;
}

public function create(string $resourceClass): ResourceMetadataCollection
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/Resources/config/metadata/resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
service('api_platform.filter_locator')->ignoreOnInvalid(),
service('api_platform.name_converter')->ignoreOnInvalid(),
service('logger')->ignoreOnInvalid(),
service('api_platform.resource_class_resolver')->ignoreOnInvalid(),
]);

$services->set('api_platform.metadata.resource.metadata_collection_factory.cached', CachedResourceMetadataCollectionFactory::class)
Expand Down
77 changes: 77 additions & 0 deletions tests/Fixtures/TestBundle/Document/FreeTextArticle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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\Document;

use ApiPlatform\Doctrine\Odm\Filter\FreeTextQueryFilter;
use ApiPlatform\Doctrine\Odm\Filter\OrFilter;
use ApiPlatform\Doctrine\Odm\Filter\PartialSearchFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\QueryParameter;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

#[ODM\Document]
#[ApiResource(
operations: [
new GetCollection(
normalizationContext: ['hydra_prefix' => false],
parameters: [
'search' => new QueryParameter(
filter: new FreeTextQueryFilter(new OrFilter(new PartialSearchFilter(caseSensitive: true))),
properties: ['content', 'tag.content'],
),
],
),
]
)]
class FreeTextArticle
{
#[ODM\Id(type: 'string', strategy: 'INCREMENT')]
private ?string $id = null;

#[ODM\Field(type: 'string')]
private string $content;

#[ODM\ReferenceOne(targetDocument: FreeTextTag::class)]
private ?FreeTextTag $tag = null;

public function getId(): ?string
{
return $this->id;
}

public function getContent(): string
{
return $this->content;
}

public function setContent(string $content): self
{
$this->content = $content;

return $this;
}

public function getTag(): ?FreeTextTag
{
return $this->tag;
}

public function setTag(?FreeTextTag $tag): self
{
$this->tag = $tag;

return $this;
}
}
43 changes: 43 additions & 0 deletions tests/Fixtures/TestBundle/Document/FreeTextTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

#[ODM\Document]
class FreeTextTag
{
#[ODM\Id(type: 'string', strategy: 'INCREMENT')]
private ?string $id = null;

#[ODM\Field(type: 'string')]
private string $content;

public function getId(): ?string
{
return $this->id;
}

public function getContent(): string
{
return $this->content;
}

public function setContent(string $content): self
{
$this->content = $content;

return $this;
}
}
88 changes: 88 additions & 0 deletions tests/Fixtures/TestBundle/Document/PostCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?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\Document;

use ApiPlatform\Doctrine\Odm\Filter\FreeTextQueryFilter;
use ApiPlatform\Doctrine\Odm\Filter\OrFilter;
use ApiPlatform\Doctrine\Odm\Filter\PartialSearchFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\QueryParameter;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

#[ODM\Document]
#[ApiResource(
shortName: 'PostCard',
operations: [
new GetCollection(
uriTemplate: '/post_cards_embedded',
normalizationContext: ['hydra_prefix' => false],
parameters: [
'citySearch' => new QueryParameter(
filter: new PartialSearchFilter(),
property: 'address.city',
),
'freeSearch' => new QueryParameter(
filter: new FreeTextQueryFilter(new OrFilter(new PartialSearchFilter())),
properties: ['address.city', 'address.street'],
),
],
),
]
)]
class PostCard
{
#[ODM\Id(type: 'string', strategy: 'INCREMENT')]
private ?string $id = null;

#[ODM\Field(type: 'string')]
private string $title;

#[ODM\EmbedOne(targetDocument: PostCardAddress::class)]
private PostCardAddress $address;

public function __construct()
{
$this->address = new PostCardAddress();
}

public function getId(): ?string
{
return $this->id;
}

public function getTitle(): string
{
return $this->title;
}

public function setTitle(string $title): self
{
$this->title = $title;

return $this;
}

public function getAddress(): PostCardAddress
{
return $this->address;
}

public function setAddress(PostCardAddress $address): self
{
$this->address = $address;

return $this;
}
}
65 changes: 65 additions & 0 deletions tests/Fixtures/TestBundle/Document/PostCardAddress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

#[ODM\EmbeddedDocument]
class PostCardAddress
{
#[ODM\Field(type: 'string')]
private string $street;

#[ODM\Field(type: 'string')]
private string $city;

#[ODM\Field(type: 'string')]
private string $zipCode;

public function getStreet(): string
{
return $this->street;
}

public function setStreet(string $street): self
{
$this->street = $street;

return $this;
}

public function getCity(): string
{
return $this->city;
}

public function setCity(string $city): self
{
$this->city = $city;

return $this;
}

public function getZipCode(): string
{
return $this->zipCode;
}

public function setZipCode(string $zipCode): self
{
$this->zipCode = $zipCode;

return $this;
}
}
Loading
Loading