| 1 |
<?php |
| 2 |
namespace Depicter\Middleware; |
| 3 |
|
| 4 |
use WPEmerge\Requests\RequestInterface; |
| 5 |
use WPEmerge\Responses\ResponseService; |
| 6 |
|
| 7 |
|
| 8 |
class CORSMiddleware |
| 9 |
{ |
| 10 |
|
| 11 |
/** |
| 12 |
* Response service. |
| 13 |
* |
| 14 |
* @var ResponseService |
| 15 |
*/ |
| 16 |
protected $responseService = null; |
| 17 |
|
| 18 |
/** |
| 19 |
* Constructor. |
| 20 |
* |
| 21 |
* @codeCoverageIgnore |
| 22 |
* @param ResponseService $responseService |
| 23 |
*/ |
| 24 |
public function __construct( ResponseService $responseService ) { |
| 25 |
$this->responseService = $responseService; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* @param RequestInterface $request |
| 30 |
* @param $next |
| 31 |
* |
| 32 |
* @return \Psr\Http\Message\ResponseInterface |
| 33 |
*/ |
| 34 |
public function handle( RequestInterface $request, $next ) { |
| 35 |
|
| 36 |
//return $this->responseService->json( $result )->withHeader('Cache-Control', 'max-age=' . $expiration ); |
| 37 |
|
| 38 |
$response = $next( $request ); |
| 39 |
|
| 40 |
$response->withHeader('Access-Control-Allow-Origin' , '*'); |
| 41 |
$response->withHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE'); |
| 42 |
$response->withHeader('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, Application'); |
| 43 |
|
| 44 |
return $response; |
| 45 |
} |
| 46 |
|
| 47 |
} |
| 48 |
|