Open ArensMyzyri opened 1 year ago
The implementation of the service looks like:
<?php
declare(strict_types=1);
namespace App\Shared\Infrastructure\Http;
use App\Product\Domain\Dto\DtoInterface;
use App\Product\Domain\NormalizerAndSerializer\ModelSerializerServiceInterface;
use App\Shared\Domain\Http\HttpResponseInterface;
use Symfony\Component\HttpFoundation\Response;
class HttpJsonResponse extends Response implements HttpResponseInterface
{
public function __construct(readonly ModelSerializerServiceInterface $serializer, readonly DtoInterface $data, readonly int $statusCode)
{
parent::__construct($this->serializer->serializeToJson($data), $statusCode, ['Content-Type' => 'application/json;charset=UTF-8']);
}
}
As you see only here I use symfony Http Response
Hey there. In the UI web controller you are using symfony http response which goes against hexagonal architecture. I would suggest to build a service in infrastructure where you implement the http response and then use its interface on your controller. Example: In Domain create MyHttpResponseInterface and implement it in MySymfonyHttpResponse class (in infrastructure), then use this interface in your controller.
Here an example how I built a controller:
Let me know what you think :)