-
Notifications
You must be signed in to change notification settings - Fork 85
IBX-8190: Update REST new resource #2682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adriendupuis
wants to merge
30
commits into
5.0
Choose a base branch
from
update-rest
base: 5.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
4a8a47a
routes_rest.yaml: Fix greet controller
adriendupuis d6a064f
Start rewrite custom rest example
adriendupuis 3b616c4
Start rewrite custom rest example
adriendupuis 296ca50
clean-up
adriendupuis 2ce1141
PHP & JS CS Fixes
adriendupuis 685ad5d
Enhance output
adriendupuis 4d8252e
PHP & JS CS Fixes
adriendupuis 0b04132
Enhance output
adriendupuis 6300ece
Denormalize input
adriendupuis 90e482d
PHP & JS CS Fixes
adriendupuis 1e76897
Add REST controller to doc
adriendupuis 72c0614
PHP & JS CS Fixes
adriendupuis 8d101f7
Add REST controller to doc
adriendupuis 749ee2e
PHP & JS CS Fixes
adriendupuis 8746a41
Start to update creating_new_rest_resource.md
adriendupuis b3f0c11
Restore RestLocation.php
adriendupuis 97d32ae
Restore ValueObjectVisitorDispatcher.php
adriendupuis 14a1c78
phpstan-baseline.neon: rm ValueObjectVisitor\Greeting err
adriendupuis cd9c883
DefaultController: Hard code root node name
adriendupuis 530d80a
GreetingInputDenormalizer.php
adriendupuis 379a4f1
GreetingNormalizer: Fix type hint & PHPDoc
adriendupuis 5a80a79
PHP & JS CS Fixes
adriendupuis fbcd437
Merge branch '5.0' into update-rest
adriendupuis bbc851f
Fix GreetingInputDenormalizer::denormalize
adriendupuis a64de31
Fix GreetingInputDenormalizer::supportsDenormalization
adriendupuis c75a1ab
Fix GreetingInputDenormalizer::getSupportedTypes
adriendupuis 0e82f5f
Fix GreetingNormalizer::normalize
adriendupuis e826328
Fix GreetingNormalizer::supportsNormalization
adriendupuis 4ef6d43
Fix GreetingNormalizer::getSupportedTypes
adriendupuis 3da7b10
creating_new_rest_resource.md: Complete TODOs
adriendupuis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 +1,6 @@ | ||
app.rest.greeting: | ||
path: '/greet' | ||
controller: App\Rest\Controller\DefaultController::helloWorld | ||
controller: App\Rest\Controller\DefaultController::greet | ||
methods: [GET,POST] | ||
defaults: | ||
csrf_protection: false |
This file contains hidden or 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 hidden or 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
20 changes: 0 additions & 20 deletions
20
code_samples/api/rest_api/src/Rest/InputParser/GreetingInput.php
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
code_samples/api/rest_api/src/Rest/Serializer/GreetingInputDenormalizer.php
This file contains hidden or 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,48 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Rest\Serializer; | ||
|
||
use App\Rest\Values\Greeting; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
|
||
class GreetingInputDenormalizer implements DenormalizerInterface, DenormalizerAwareInterface | ||
{ | ||
use DenormalizerAwareTrait; | ||
|
||
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed | ||
{ | ||
if ('json' === $format) { | ||
$data = $data[array_key_first($data)]; | ||
} | ||
$data = array_change_key_case($data); | ||
adriendupuis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$salutation = $data['salutation'] ?? 'Hello'; | ||
$recipient = $data['recipient'] ?? 'World'; | ||
|
||
return new Greeting($salutation, $recipient); | ||
} | ||
|
||
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool | ||
{ | ||
if (!is_array($data)) { | ||
return false; | ||
} | ||
|
||
if ('json' === $format) { | ||
$data = $data[array_key_first($data)]; | ||
} | ||
$data = array_change_key_case($data); | ||
|
||
return in_array($type, $this->getSupportedTypes($format), true) && | ||
(array_key_exists('salutation', $data) || array_key_exists('recipient', $data)); | ||
} | ||
|
||
public function getSupportedTypes(?string $format): array | ||
{ | ||
return [ | ||
Greeting::class => true, | ||
]; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unwrap JSON.
I could even test that
'GreetingInput' === array_key_first($data)