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
class RouteGroup
8
{
9
    /**
10
     * Merge route groups into a new array.
11
     *
12
     * @param  array  $new
13
     * @param  array  $old
14
     * @param  bool  $prependExistingPrefix
15
     * @return array
16
     */
17
    public static function merge($new, $old, $prependExistingPrefix = true)
18
    {
19
        if (isset($new['domain'])) {
20
            unset($old['domain']);
21
        }
22
 
23
        if (isset($new['controller'])) {
24
            unset($old['controller']);
25
        }
26
 
27
        $new = array_merge(static::formatAs($new, $old), [
28
            'namespace' => static::formatNamespace($new, $old),
29
            'prefix' => static::formatPrefix($new, $old, $prependExistingPrefix),
30
            'where' => static::formatWhere($new, $old),
31
        ]);
32
 
33
        return array_merge_recursive(Arr::except(
34
            $old, ['namespace', 'prefix', 'where', 'as']
35
        ), $new);
36
    }
37
 
38
    /**
39
     * Format the namespace for the new group attributes.
40
     *
41
     * @param  array  $new
42
     * @param  array  $old
43
     * @return string|null
44
     */
45
    protected static function formatNamespace($new, $old)
46
    {
47
        if (isset($new['namespace'])) {
48
            return isset($old['namespace']) && ! str_starts_with($new['namespace'], '\\')
49
                    ? trim($old['namespace'], '\\').'\\'.trim($new['namespace'], '\\')
50
                    : trim($new['namespace'], '\\');
51
        }
52
 
53
        return $old['namespace'] ?? null;
54
    }
55
 
56
    /**
57
     * Format the prefix for the new group attributes.
58
     *
59
     * @param  array  $new
60
     * @param  array  $old
61
     * @param  bool  $prependExistingPrefix
62
     * @return string|null
63
     */
64
    protected static function formatPrefix($new, $old, $prependExistingPrefix = true)
65
    {
66
        $old = $old['prefix'] ?? '';
67
 
68
        if ($prependExistingPrefix) {
69
            return isset($new['prefix']) ? trim($old, '/').'/'.trim($new['prefix'], '/') : $old;
70
        } else {
71
            return isset($new['prefix']) ? trim($new['prefix'], '/').'/'.trim($old, '/') : $old;
72
        }
73
    }
74
 
75
    /**
76
     * Format the "wheres" for the new group attributes.
77
     *
78
     * @param  array  $new
79
     * @param  array  $old
80
     * @return array
81
     */
82
    protected static function formatWhere($new, $old)
83
    {
84
        return array_merge(
85
            $old['where'] ?? [],
86
            $new['where'] ?? []
87
        );
88
    }
89
 
90
    /**
91
     * Format the "as" clause of the new group attributes.
92
     *
93
     * @param  array  $new
94
     * @param  array  $old
95
     * @return array
96
     */
97
    protected static function formatAs($new, $old)
98
    {
99
        if (isset($old['as'])) {
100
            $new['as'] = $old['as'].($new['as'] ?? '');
101
        }
102
 
103
        return $new;
104
    }
105
}