Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation\Http\Middleware;
4
 
5
use Closure;
6
use Symfony\Component\HttpFoundation\ParameterBag;
7
 
8
class TransformsRequest
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @param  \Closure  $next
15
     * @return mixed
16
     */
17
    public function handle($request, Closure $next)
18
    {
19
        $this->clean($request);
20
 
21
        return $next($request);
22
    }
23
 
24
    /**
25
     * Clean the request's data.
26
     *
27
     * @param  \Illuminate\Http\Request  $request
28
     * @return void
29
     */
30
    protected function clean($request)
31
    {
32
        $this->cleanParameterBag($request->query);
33
 
34
        if ($request->isJson()) {
35
            $this->cleanParameterBag($request->json());
36
        } elseif ($request->request !== $request->query) {
37
            $this->cleanParameterBag($request->request);
38
        }
39
    }
40
 
41
    /**
42
     * Clean the data in the parameter bag.
43
     *
44
     * @param  \Symfony\Component\HttpFoundation\ParameterBag  $bag
45
     * @return void
46
     */
47
    protected function cleanParameterBag(ParameterBag $bag)
48
    {
49
        $bag->replace($this->cleanArray($bag->all()));
50
    }
51
 
52
    /**
53
     * Clean the data in the given array.
54
     *
55
     * @param  array  $data
56
     * @param  string  $keyPrefix
57
     * @return array
58
     */
59
    protected function cleanArray(array $data, $keyPrefix = '')
60
    {
61
        foreach ($data as $key => $value) {
62
            $data[$key] = $this->cleanValue($keyPrefix.$key, $value);
63
        }
64
 
65
        return $data;
66
    }
67
 
68
    /**
69
     * Clean the given value.
70
     *
71
     * @param  string  $key
72
     * @param  mixed  $value
73
     * @return mixed
74
     */
75
    protected function cleanValue($key, $value)
76
    {
77
        if (is_array($value)) {
78
            return $this->cleanArray($value, $key.'.');
79
        }
80
 
81
        return $this->transform($key, $value);
82
    }
83
 
84
    /**
85
     * Transform the given value.
86
     *
87
     * @param  string  $key
88
     * @param  mixed  $value
89
     * @return mixed
90
     */
91
    protected function transform($key, $value)
92
    {
93
        return $value;
94
    }
95
}