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 Illuminate\Http\Exceptions\PostTooLargeException;
7
 
8
class ValidatePostSize
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @param  \Closure  $next
15
     * @return mixed
16
     *
17
     * @throws \Illuminate\Http\Exceptions\PostTooLargeException
18
     */
19
    public function handle($request, Closure $next)
20
    {
21
        $max = $this->getPostMaxSize();
22
 
23
        if ($max > 0 && $request->server('CONTENT_LENGTH') > $max) {
24
            throw new PostTooLargeException;
25
        }
26
 
27
        return $next($request);
28
    }
29
 
30
    /**
31
     * Determine the server 'post_max_size' as bytes.
32
     *
33
     * @return int
34
     */
35
    protected function getPostMaxSize()
36
    {
37
        if (is_numeric($postMaxSize = ini_get('post_max_size'))) {
38
            return (int) $postMaxSize;
39
        }
40
 
41
        $metric = strtoupper(substr($postMaxSize, -1));
42
        $postMaxSize = (int) $postMaxSize;
43
 
44
        return match ($metric) {
45
            'K' => $postMaxSize * 1024,
46
            'M' => $postMaxSize * 1048576,
47
            'G' => $postMaxSize * 1073741824,
48
            default => $postMaxSize,
49
        };
50
    }
51
}