Skip to content

Commit 80fd040

Browse files
committed
Added response trait
1 parent 5679562 commit 80fd040

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/Statflo/HTTP/Controller/ContainerController.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,5 @@
77

88
abstract class ContainerController extends ContainerAware
99
{
10-
protected function response($data, $statusCode = 200)
11-
{
12-
$data = new Response($statusCode, $data);
13-
14-
return new JsonResponse(
15-
$data,
16-
$statusCode,
17-
[
18-
'X-Status-Code' => $statusCode,
19-
'X-Session-Length' => strlen(var_export($_SESSION, true)),
20-
]
21-
);
22-
}
10+
use Statflo\HTTP\ResponseTrait;
2311
}

src/Statflo/HTTP/ResponseTrait.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
namespace Statflo\HTTP;
3+
4+
use Symfony\Component\HttpFoundation\JsonResponse;
5+
use Statflo\HTTP\DTO\Response;
6+
7+
trait ResponseTrait
8+
{
9+
public function response($data, $statusCode = 200)
10+
{
11+
$data = new Response($statusCode, $data);
12+
13+
return new JsonResponse(
14+
$data,
15+
$statusCode,
16+
[
17+
'X-Status-Code' => $statusCode,
18+
'X-Session-Length' => strlen(var_export($_SESSION, true)),
19+
]
20+
);
21+
}
22+
}

0 commit comments

Comments
 (0)