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\Routing;
4
 
5
use Illuminate\Support\Arr;
6
 
7
trait CreatesRegularExpressionRouteConstraints
8
{
9
    /**
10
     * Specify that the given route parameters must be alphabetic.
11
     *
12
     * @param  array|string  $parameters
13
     * @return $this
14
     */
15
    public function whereAlpha($parameters)
16
    {
17
        return $this->assignExpressionToParameters($parameters, '[a-zA-Z]+');
18
    }
19
 
20
    /**
21
     * Specify that the given route parameters must be alphanumeric.
22
     *
23
     * @param  array|string  $parameters
24
     * @return $this
25
     */
26
    public function whereAlphaNumeric($parameters)
27
    {
28
        return $this->assignExpressionToParameters($parameters, '[a-zA-Z0-9]+');
29
    }
30
 
31
    /**
32
     * Specify that the given route parameters must be numeric.
33
     *
34
     * @param  array|string  $parameters
35
     * @return $this
36
     */
37
    public function whereNumber($parameters)
38
    {
39
        return $this->assignExpressionToParameters($parameters, '[0-9]+');
40
    }
41
 
42
    /**
43
     * Specify that the given route parameters must be ULIDs.
44
     *
45
     * @param  array|string  $parameters
46
     * @return $this
47
     */
48
    public function whereUlid($parameters)
49
    {
50
        return $this->assignExpressionToParameters($parameters, '[0-7][0-9a-hjkmnp-tv-zA-HJKMNP-TV-Z]{25}');
51
    }
52
 
53
    /**
54
     * Specify that the given route parameters must be UUIDs.
55
     *
56
     * @param  array|string  $parameters
57
     * @return $this
58
     */
59
    public function whereUuid($parameters)
60
    {
61
        return $this->assignExpressionToParameters($parameters, '[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}');
62
    }
63
 
64
    /**
65
     * Specify that the given route parameters must be one of the given values.
66
     *
67
     * @param  array|string  $parameters
68
     * @param  array  $values
69
     * @return $this
70
     */
71
    public function whereIn($parameters, array $values)
72
    {
73
        return $this->assignExpressionToParameters($parameters, implode('|', $values));
74
    }
75
 
76
    /**
77
     * Apply the given regular expression to the given parameters.
78
     *
79
     * @param  array|string  $parameters
80
     * @param  string  $expression
81
     * @return $this
82
     */
83
    protected function assignExpressionToParameters($parameters, $expression)
84
    {
85
        return $this->where(collect(Arr::wrap($parameters))
86
                    ->mapWithKeys(fn ($parameter) => [$parameter => $expression])
87
                    ->all());
88
    }
89
}