Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
698 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
```php | ||
// how to give uidfilter the parameters it should declare? | ||
// is it automatic if we find a property having the uid type? | ||
#[Get(filters: [new SearchFilter(), new UidFilter()]) | ||
#[Parameter('key', schema: ['type' => 'string'])] // add transform + validate extension points | ||
class Book { | ||
|
||
} | ||
|
||
final class Parameter { | ||
mixed $value; | ||
?string $property; | ||
?string $class; | ||
array $attributes; | ||
} | ||
|
||
class FilterInterface {} | ||
|
||
class UidFilter { | ||
public function __construct(private readonly string $class) {} | ||
|
||
public function parseQueryParameter(array $queryParameters = []): Parameter[] { | ||
return [ | ||
new Parameter(value: '', attributes: ['operation' => 'and']) | ||
]; | ||
} | ||
|
||
// Query parameter type | ||
public function getSchema(): array { | ||
return ['type' => 'string']; | ||
} | ||
|
||
public function getOpenApiParameter(): OpenApi\Parameter { | ||
return ...; | ||
} | ||
} | ||
|
||
public function process(Operation $operation) { | ||
$request = $context['request']; | ||
|
||
foreach($operation->getFilters() as $filter) { | ||
foreach ($filter->parseQueryParameter($request->query, $context) as $parameter) { | ||
$this->queryParameterValidator->validate($filter, $parameter, $context); | ||
$filter->execute($filter, $parameter, $context); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
TODO: | ||
see SerializerFilterContextBuilder: public function apply(Request $request, bool $normalization, array $attributes, array &$context): void; | ||
maybe something like: | ||
|
||
``` | ||
class SerializerFilterInterface { | ||
public function getNormalizationContext(...); | ||
public function getDenormalizationContext(...); | ||
} | ||
``` | ||
|
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 |
---|---|---|
@@ -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\Metadata; | ||
|
||
class HeaderParameter extends Parameter implements HeaderParameterInterface | ||
{ | ||
} |
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 |
---|---|---|
@@ -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\Metadata; | ||
|
||
interface HeaderParameterInterface | ||
{ | ||
} |
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
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,16 +1,119 @@ | ||
<?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\Metadata; | ||
|
||
use ApiPlatform\OpenApi; | ||
use ApiPlatform\State\ProviderInterface; | ||
|
||
abstract class Parameter | ||
{ | ||
/** | ||
* @param array<string, mixed> $extraProperties | ||
* @param ProviderInterface|string|null $provider | ||
* @param FilterInterface|string|null $filter | ||
*/ | ||
public function __construct( | ||
protected ?string $key = null, | ||
protected ?\ArrayObject $schema = null, | ||
protected ?OpenApi\Model\Parameter $openApi = null, | ||
protected mixed $provider = null, | ||
protected mixed $filter = null, | ||
protected array $extraProperties = [], | ||
) { | ||
} | ||
|
||
public function getKey(): ?string | ||
{ | ||
return $this->key; | ||
} | ||
|
||
public function getSchema(): ?\ArrayObject | ||
{ | ||
return $this->schema; | ||
} | ||
|
||
public function getOpenApi(): ?OpenApi\Model\Parameter | ||
{ | ||
return $this->openApi; | ||
} | ||
|
||
public function getProvider(): mixed | ||
{ | ||
return $this->provider; | ||
} | ||
|
||
public function getFilter(): mixed | ||
{ | ||
return $this->filter; | ||
} | ||
|
||
public function getExtraProperties(): ?array | ||
{ | ||
return $this->extraProperties; | ||
} | ||
|
||
public function withKey(?string $key): static | ||
{ | ||
$self = clone $this; | ||
$self->key = $key; | ||
|
||
return $self; | ||
} | ||
|
||
/** | ||
* @param \ArrayObject<string,mixed> $schema | ||
*/ | ||
public function withSchema(\ArrayObject $schema): static | ||
{ | ||
$self = clone $this; | ||
$self->schema = $schema; | ||
|
||
return $self; | ||
} | ||
|
||
public function withOpenApi(OpenApi\Model\Parameter $openApi): static | ||
{ | ||
$self = clone $this; | ||
$self->openApi = $openApi; | ||
|
||
return $self; | ||
} | ||
|
||
public function withProvider(mixed $provider): static | ||
{ | ||
$self = clone $this; | ||
$self->provider = $provider; | ||
|
||
return $self; | ||
} | ||
|
||
public function withFilter(mixed $filter): static | ||
{ | ||
$self = clone $this; | ||
$self->filter = $filter; | ||
|
||
return $self; | ||
} | ||
|
||
final class Parameter { | ||
public string $key; | ||
public \ArrayObject $schema; | ||
public array $context; | ||
public ?OpenApi\Model\Parameter $openApi; | ||
/** | ||
* @param fn(mixed $value, Parameter $parameter, array $context)|string|null | ||
* @param array<string, mixed> $extraProperties | ||
*/ | ||
public mixed $provider; | ||
public function withExtraProperties(array $extraProperties = []): static | ||
{ | ||
$self = clone $this; | ||
$self->extraProperties = $extraProperties; | ||
|
||
return $self; | ||
} | ||
} |
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 |
---|---|---|
@@ -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\Metadata; | ||
|
||
class QueryParameter extends Parameter implements QueryParameterInterface | ||
{ | ||
} |
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 |
---|---|---|
@@ -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\Metadata; | ||
|
||
interface QueryParameterInterface | ||
{ | ||
} |
Oops, something went wrong.