Skip to content

Commit

Permalink
Applied review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Aug 27, 2024
1 parent 5ed48da commit 1bab293
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
6 changes: 1 addition & 5 deletions src/bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,13 @@ services:
tags:
- ibexa.rest.serializer.encoder

Ibexa\Contracts\Rest\Output\AdapterNormalizer:
Ibexa\Contracts\Rest\Output\VisitorAdapterNormalizer:
arguments:
$encoder: '@ibexa.rest.serializer.encoder.json'
$valueObjectVisitorResolver: '@Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolver'
tags:
- { name: ibexa.rest.serializer.normalizer, priority: -1000 }

Ibexa\Rest\Output\Normalizer\TestNormalizer:
tags:
- ibexa.rest.serializer.normalizer

Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolverInterface: '@Ibexa\Contracts\Rest\Output\ValueObjectVisitor'

Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolver: ~
2 changes: 1 addition & 1 deletion src/contracts/Output/ValueObjectVisitorResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class ValueObjectVisitorResolver implements ValueObjectVisitorResolverInte
/**
* @param class-string $visitedClassName
*/
public function addVisitor(string $visitedClassName, $visitor): void
public function addVisitor(string $visitedClassName, ValueObjectVisitor $visitor): void
{
$this->visitors[$visitedClassName] = $visitor;
}
Expand Down
15 changes: 1 addition & 14 deletions src/contracts/Output/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
namespace Ibexa\Contracts\Rest\Output;

use Error;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Rest\Output\Normalizer\TestData;
use Ibexa\Rest\Server\Values\RestLocation;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
Expand All @@ -36,7 +33,6 @@ public function __construct(
private readonly NormalizerInterface $normalizer,
private readonly EncoderInterface $encoder,
private readonly ValueObjectVisitorResolverInterface $valueObjectVisitorResolver,
private readonly ?LocationService $locationService = null, //TODO to remove
) {
$this->response = new Response('', 200);
}
Expand Down Expand Up @@ -74,18 +70,9 @@ public function setStatus($statusCode)

/**
* Visit struct returned by controllers.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function visit(mixed $data)
public function visit(mixed $data): Response
{
//TODO to remove
$data = new TestData();
$data->setName('test test');
$location = $this->locationService->loadLocation(2);
$location = new RestLocation($location, 2);
$data->setLocation($location);

$normalizedData = $this->normalizer->normalize($data);

//@todo Needs refactoring!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
namespace Ibexa\Contracts\Rest\Output;

use Ibexa\Rest\Output\Generator\Json;
use LogicException;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

final class AdapterNormalizer implements NormalizerInterface, NormalizerAwareInterface, ContextAwareNormalizerInterface
final class VisitorAdapterNormalizer implements NormalizerInterface, NormalizerAwareInterface, ContextAwareNormalizerInterface
{
use NormalizerAwareTrait;

Expand Down Expand Up @@ -60,6 +61,16 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
return true;
}

if (!$this->normalizer instanceof ContextAwareNormalizerInterface) {
throw new LogicException(
sprintf(
'Normalizer "%s" must be an instance of "%s".',
$this->normalizer::class,
ContextAwareNormalizerInterface::class,
)
);
}

return $this->normalizer->supportsNormalization(
$data,
null,
Expand Down

0 comments on commit 1bab293

Please sign in to comment.