-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(state): parameter decorates main chain (#6434)
* fix(state): parameter decorates main chain * fix: property placeholder validation
- Loading branch information
Showing
16 changed files
with
187 additions
and
61 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,53 @@ | ||
<?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\State\Util; | ||
|
||
use ApiPlatform\Metadata\HeaderParameterInterface; | ||
use ApiPlatform\Metadata\Parameter; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
trait ParameterParserTrait | ||
{ | ||
/** | ||
* @param array<string, mixed> $values | ||
*/ | ||
private function getParameterFlattenKey(string $key, array $values): string | ||
{ | ||
$parsedKey = explode('[:property]', $key); | ||
|
||
if (isset($parsedKey[0]) && isset($values[$parsedKey[0]])) { | ||
return $parsedKey[0]; | ||
} | ||
|
||
return $key; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $context | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
private function extractParameterValues(Parameter $parameter, ?Request $request, array $context): array | ||
{ | ||
if ($request) { | ||
return ($parameter instanceof HeaderParameterInterface ? $request->attributes->get('_api_header_parameters') : $request->attributes->get('_api_query_parameters')) ?? []; | ||
} | ||
|
||
// GraphQl | ||
return $context['args'] ?? []; | ||
} | ||
} |
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
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
11 changes: 0 additions & 11 deletions
11
src/Symfony/Bundle/Resources/config/symfony/parameter_validator.xml
This file was deleted.
Oops, something went wrong.
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
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
42 changes: 42 additions & 0 deletions
42
tests/Fixtures/TestBundle/ApiResource/ValidateParameterBeforeProvider.php
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,42 @@ | ||
<?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; | ||
|
||
use ApiPlatform\Metadata\GetCollection; | ||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\Metadata\QueryParameter; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Validator\Constraints\Choice; | ||
use Symfony\Component\Validator\Constraints\Collection; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
|
||
#[GetCollection( | ||
uriTemplate: 'query_parameter_validate_before_read', | ||
parameters: [ | ||
'search' => new QueryParameter(constraints: [new NotBlank()]), | ||
'sort[:property]' => new QueryParameter(constraints: [new NotBlank(), new Collection(['id' => new Choice(['asc', 'desc'])], allowMissingFields: true)]), | ||
], | ||
provider: [self::class, 'provide'] | ||
)] | ||
class ValidateParameterBeforeProvider | ||
{ | ||
public static function provide(Operation $operation, array $uriVariables = [], array $context = []) | ||
{ | ||
if (!$context['request']->query->get('search')) { | ||
throw new \RuntimeException('Not supposed to happen'); | ||
} | ||
|
||
return new JsonResponse(204); | ||
} | ||
} |
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
Oops, something went wrong.