dev-think-one /
nova-flexible-content
| 1 | <?php |
||
| 2 | |||
| 3 | namespace NovaFlexibleContent\Http\Middleware; |
||
| 4 | |||
| 5 | use Closure; |
||
| 6 | use Illuminate\Http\Request; |
||
| 7 | use NovaFlexibleContent\Http\FlexibleAttribute; |
||
| 8 | use NovaFlexibleContent\Http\ParsesFlexibleAttributes; |
||
| 9 | use NovaFlexibleContent\Http\TransformsFlexibleErrors; |
||
| 10 | use Symfony\Component\HttpFoundation\Response; |
||
| 11 | |||
| 12 | class InterceptFlexibleAttributes |
||
| 13 | { |
||
| 14 | use ParsesFlexibleAttributes; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 15 | use TransformsFlexibleErrors; |
||
|
0 ignored issues
–
show
|
|||
| 16 | |||
| 17 | /** |
||
| 18 | * Handle the given request and get the response. |
||
| 19 | * |
||
| 20 | * @param \Illuminate\Http\Request $request |
||
| 21 | * @param \Closure $next |
||
| 22 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 23 | */ |
||
| 24 | 9 | public function handle(Request $request, Closure $next) : Response |
|
| 25 | { |
||
| 26 | |||
| 27 | 9 | if (!$this->requestHasParsableFlexibleInputs($request)) { |
|
| 28 | 4 | return $next($request); |
|
| 29 | } |
||
| 30 | |||
| 31 | 5 | $request->merge($this->getParsedFlexibleInputs($request)); |
|
| 32 | 5 | $request->request->remove(FlexibleAttribute::REGISTER_FLEXIBLE_FIELD_NAME); |
|
| 33 | |||
| 34 | 5 | $response = $next($request); |
|
| 35 | |||
| 36 | 5 | if (!$this->shouldTransformFlexibleErrors($response)) { |
|
| 37 | 4 | return $response; |
|
| 38 | } |
||
| 39 | |||
| 40 | 1 | return $this->transformFlexibleErrors($response); |
|
| 41 | } |
||
| 42 | } |
||
| 43 |