mtvbrianking /
laravel-xml
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Bmatovu\LaravelXml\Http\Middleware; |
||
| 4 | |||
| 5 | use Bmatovu\LaravelXml\LaravelXml; |
||
| 6 | use Closure; |
||
| 7 | |||
| 8 | class RequireXml |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Handle an incoming request. |
||
| 12 | * |
||
| 13 | * @see https://stackoverflow.com/a/11973933/2732184 |
||
| 14 | * |
||
| 15 | * @param \Illuminate\Http\Request $request |
||
| 16 | * @param bool $isValidXml |
||
| 17 | * |
||
| 18 | * @return mixed |
||
| 19 | */ |
||
| 20 | 1 | public function handle($request, Closure $next, $isValidXml = false) |
|
| 21 | { |
||
| 22 | 1 | if ('xml' !== $request->getContentTypeFormat()) { |
|
| 23 | 1 | return response()->xml(['message' => 'Only accepting content of type XML.'], 415); |
|
| 24 | } |
||
| 25 | |||
| 26 | if ($isValidXml && $request->getContent() && ! LaravelXml::is_valid($request->getContent())) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 27 | return response()->xml(['message' => 'The given data was malformed.'], 400); |
||
| 28 | } |
||
| 29 | |||
| 30 | return $next($request); |
||
| 31 | } |
||
| 32 | } |
||
| 33 |