diff --git a/.gitignore b/.gitignore index 86bfd55..d886f85 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ phpbench.json phpcs.xml phpunit.xml vendor/ +.idea diff --git a/README.md b/README.md index 662b57c..f90ae59 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,5 @@ ## Installation (via composer) ```bash -composer require 'arus/http-response-kit:^1.3' +composer require 'autorusltd/http-response-kit:^2.1' ``` diff --git a/composer.json b/composer.json index bf0177e..617077e 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "require-dev": { "phpunit/phpunit": "7.5.20|9.5.0", "arus/php-coding-standard": "^1.0", - "sunrise/http-message": "^1.3", + "sunrise/http-message": "^3.0.0", "laminas/laminas-diactoros": "^2.4|^2.5", "symfony/validator": "^4.0" }, diff --git a/src/ResponseFactoryAwareTrait.php b/src/ResponseFactoryAwareTrait.php index af9b58d..76a2652 100644 --- a/src/ResponseFactoryAwareTrait.php +++ b/src/ResponseFactoryAwareTrait.php @@ -7,7 +7,9 @@ */ use Arus\Http\Response\Resource\Error; use Arus\Http\Response\Resource\Errors; +use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; +use Sunrise\Http\Message\Response\HtmlResponse; use Sunrise\Http\Message\ResponseFactory; use Symfony\Component\Validator\ConstraintViolationInterface; use InvalidArgumentException; @@ -33,11 +35,6 @@ trait ResponseFactoryAwareTrait */ protected $jsonOptions = 0; - /** - * @var int - */ - protected $jsonDepth = 512; - /** * @param int $status * @@ -45,8 +42,9 @@ trait ResponseFactoryAwareTrait */ public function createResponse(int $status = 200) : ResponseInterface { - return (new $this->responseFactory) - ->createResponse($status); + /** @var ResponseFactory $factory */ + $factory = (new $this->responseFactory); + return $factory->createResponse($status); } /** @@ -57,20 +55,19 @@ public function createResponse(int $status = 200) : ResponseInterface */ public function html($content, int $status = 200) : ResponseInterface { - return (new $this->responseFactory) - ->createHtmlResponse($status, $content); + return new HtmlResponse($status, $content); } /** * @param mixed $payload * @param int $status + * @param array $headers * * @return ResponseInterface */ - public function json($payload, int $status = 200) : ResponseInterface + public function json($payload, int $status = 200, array $headers = []) : ResponseInterface { - return (new $this->responseFactory) - ->createJsonResponse($status, $payload, $this->jsonOptions, $this->jsonDepth); + return new JsonResponse($status, $payload, $headers, $this->jsonOptions); } /** @@ -90,7 +87,7 @@ public function ok($data = [], array $meta = [], int $status = 200) : ResponseIn /** * @param string $message - * @param string $source + * @param string|null $source * @param mixed $code * @param int $status *