Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Latest commit

 

History

History
49 lines (37 loc) · 1 KB

ResponseManager.md

File metadata and controls

49 lines (37 loc) · 1 KB

ResponseManager

<?php

use Chubbyphp\ApiHttp\Factory\ResponseFactoryInterface;
use Chubbyphp\ApiHttp\Manager\ResponseManager;
use Chubbyphp\Deserialization\DeserializerInterface;
use Chubbyphp\HttpException\HttpExceptionInterface;
use Chubbyphp\Serialization\SerializerInterface;

/** @var DeserializerInterface $deserializer */
$deserializer = ...;

/** @var ResponseFactoryInterface $responseFactory */
$responseFactory = ...;

/** @var SerializerInterface $serializer */
$serializer = ...;

$responseManager = new ResponseManager(
    $deserializer,
    $responseFactory,
    $serializer
);

$object = ...;

$response = $responseManager->create(
    $object,
    'application/json'
);

$response = $responseManager->createEmpty(
    'application/json'
);

$response = $responseManager->createRedirect(
    'https://www.google.com'
);

/** @var HttpExceptionInterface $httpException */
$httpException = ...;

$response = $responseManager->createFromHttpException(
    $httpException,
    'application/json'
);