Skip to content

Commit d6a064f

Browse files
committed
Start rewrite custom rest example
1 parent 4a8a47a commit d6a064f

File tree

6 files changed

+55
-145
lines changed

6 files changed

+55
-145
lines changed

code_samples/api/rest_api/src/Rest/Controller/DefaultController.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,35 @@
22

33
namespace App\Rest\Controller;
44

5+
use ApiPlatform\Metadata\Get;
6+
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
7+
use ApiPlatform\OpenApi\Model;
58
use App\Rest\Values\Greeting;
6-
use Ibexa\Rest\Message;
79
use Ibexa\Rest\Server\Controller;
810
use Symfony\Component\HttpFoundation\Request;
11+
use Symfony\Component\HttpFoundation\Response;
912

13+
#[Get(
14+
uriTemplate: '/greet',
15+
extraProperties: [OpenApiFactory::OVERRIDE_OPENAPI_RESPONSES => false],
16+
openapi: new Model\Operation(
17+
summary: 'TODO: Greet',
18+
description: 'TODO',
19+
tags: [
20+
'User',
21+
],
22+
responses: [
23+
Response::HTTP_OK => [
24+
'description' => 'TODO',
25+
],
26+
],
27+
),
28+
)]
1029
class DefaultController extends Controller
1130
{
1231
public function greet(Request $request): Greeting
1332
{
14-
if ('POST' === $request->getMethod()) {
15-
return $this->inputDispatcher->parse(
16-
new Message(
17-
['Content-Type' => $request->headers->get('Content-Type')],
18-
$request->getContent()
19-
)
20-
);
21-
}
22-
2333
return new Greeting();
34+
//return new Response('TEST');
2435
}
2536
}

code_samples/api/rest_api/src/Rest/InputParser/GreetingInput.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

code_samples/api/rest_api/src/Rest/Output/ValueObjectVisitorDispatcher.php

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\Rest\Serializer;
4+
5+
use App\Rest\Values\Greeting;
6+
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
7+
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
8+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
9+
10+
/**
11+
* @method array getSupportedTypes(?string $format)
12+
*/
13+
class GreetingNormalizer implements NormalizerInterface, NormalizerAwareInterface
14+
{
15+
use NormalizerAwareTrait;
16+
17+
public function supportsNormalization(mixed $data, ?string $format = null)
18+
{
19+
return $data instanceof Greeting;
20+
}
21+
22+
/**
23+
* @param Greeting $object
24+
*/
25+
public function normalize(mixed $object, ?string $format = null, array $context = []): array
26+
{
27+
return $this->normalizer->normalize(['greeting' => [
28+
'salutation' => $object->salutation,
29+
'recipient' => $object->recipient,
30+
'sentence' => "{$object->salutation} {$object->recipient}",
31+
]], $format, $context);
32+
//var_dump($object);die('TODO: Implement normalize() method.');
33+
}
34+
}

code_samples/api/rest_api/src/Rest/ValueObjectVisitor/Greeting.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

code_samples/api/rest_api/src/Rest/ValueObjectVisitor/RestLocation.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)