for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Sarala\Http\Middleware;
use Closure;
use Sarala\Exceptions\NotAcceptableMediaTypeHttpException;
use Sarala\Exceptions\UnsupportedMediaTypeHttpException;
use Sarala\Sarala;
class ContentNegotiation
{
public function handle($request, Closure $next)
$supportedMediaTypes = resolve(Sarala::class)->getSupportedMediaTypes();
if (! in_array($request->header('Content-Type'), $supportedMediaTypes)) {
throw new UnsupportedMediaTypeHttpException();
}
if (! $request->accepts($supportedMediaTypes)) {
throw new NotAcceptableMediaTypeHttpException();
$response = $next($request);
$response->header('Content-Type', $request->header('Accept'));
return $response;