1 | <?php |
||
7 | class Apps |
||
8 | { |
||
9 | /** |
||
10 | * The container instance. |
||
11 | * |
||
12 | * @var \Illuminate\Contracts\Container\Container |
||
13 | */ |
||
14 | protected $container; |
||
15 | |||
16 | /** |
||
17 | * The current application identifier. |
||
18 | * |
||
19 | * @var string|false |
||
20 | */ |
||
21 | protected $id = false; |
||
22 | |||
23 | /** |
||
24 | * Create a new Apps instance. |
||
25 | * |
||
26 | * @param \Illuminate\Contracts\Container\Container $container |
||
27 | */ |
||
28 | 10 | public function __construct(Container $container) |
|
29 | { |
||
30 | 10 | $this->container = $container; |
|
31 | |||
32 | $this->container->rebinding('request', function () { |
||
33 | 1 | $this->refreshId(); |
|
34 | 10 | }); |
|
35 | 10 | } |
|
36 | |||
37 | /** |
||
38 | * Get or check the current application identifier. |
||
39 | * |
||
40 | * @return string|bool |
||
41 | */ |
||
42 | 3 | public function id() |
|
54 | |||
55 | /** |
||
56 | * Refresh the current application identifier. |
||
57 | * |
||
58 | * @return $this |
||
59 | */ |
||
60 | 2 | public function refreshId() |
|
66 | |||
67 | /** |
||
68 | * Get application identifier for the given URL. |
||
69 | * |
||
70 | * @param string $url |
||
71 | * @return string |
||
72 | */ |
||
73 | 4 | public function idForUrl($url) |
|
74 | { |
||
75 | 4 | return collect($this->container['config']['apps.url']) |
|
76 | ->filter(function ($root) use ($url) { |
||
77 | 4 | return $this->urlHasRoot($url, $root); |
|
78 | 4 | }) |
|
79 | 4 | ->sortByDesc(function ($root) { |
|
80 | 4 | return strlen($root); |
|
81 | 4 | }) |
|
82 | 4 | ->keys() |
|
83 | 4 | ->first(); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * Determine if an URL has the given root URL. |
||
88 | * |
||
89 | * @param string $url |
||
90 | * @param string $root |
||
91 | * @param bool $strict |
||
92 | * @return bool |
||
93 | */ |
||
94 | 4 | protected function urlHasRoot($url, $root, $strict = false) |
|
103 | |||
104 | /** |
||
105 | * Remove scheme for an URL. |
||
106 | * |
||
107 | * @param string $url |
||
108 | * @return string |
||
109 | */ |
||
110 | 4 | protected function removeScheme($url) |
|
114 | |||
115 | /** |
||
116 | * Get the root URL for the given application identifier. |
||
117 | * |
||
118 | * @param string $appId |
||
119 | * @return string |
||
120 | */ |
||
121 | 4 | public function root($appId = '') |
|
126 | |||
127 | /** |
||
128 | * Get the domain for the given application identifier. |
||
129 | * |
||
130 | * @param string $appId |
||
131 | * @return string |
||
132 | */ |
||
133 | 1 | public function domain($appId = '') |
|
137 | |||
138 | /** |
||
139 | * Get the URL prefix for the given application identifier. |
||
140 | * |
||
141 | * @param string $appId |
||
142 | * @return string |
||
143 | */ |
||
144 | 1 | public function prefix($appId = '') |
|
148 | |||
149 | /** |
||
150 | * Generate an absolute URL to a path for the given application identifier. |
||
151 | * |
||
152 | * @param string $appId |
||
153 | * @param string $path |
||
154 | * @param mixed $extra |
||
155 | * @return string |
||
156 | */ |
||
157 | 1 | public function url($appId = '', $path = '', $extra = []) |
|
164 | |||
165 | /** |
||
166 | * Return the remainder of a string after a given value. |
||
167 | * |
||
168 | * @param string $subject |
||
169 | * @param string $search |
||
170 | * @return string |
||
171 | */ |
||
172 | 1 | protected function stringAfter($subject, $search) |
|
176 | } |
||
177 |