1 | <?php |
||
10 | class AppManager |
||
11 | { |
||
12 | use Macroable; |
||
13 | |||
14 | /** |
||
15 | * The container instance. |
||
16 | * |
||
17 | * @var \Illuminate\Contracts\Container\Container |
||
18 | */ |
||
19 | protected $container; |
||
20 | |||
21 | /** |
||
22 | * The current application identifier. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $appId; |
||
27 | |||
28 | /** |
||
29 | * Create a new app manager instance. |
||
30 | * |
||
31 | * @param \Illuminate\Contracts\Container\Container $container |
||
32 | */ |
||
33 | 20 | public function __construct(Container $container) |
|
34 | { |
||
35 | 20 | $this->container = $container; |
|
36 | |||
37 | 20 | $this->container->rebinding('request', function () { |
|
38 | 2 | $this->refreshId(); |
|
39 | 20 | }); |
|
40 | 20 | } |
|
41 | |||
42 | /** |
||
43 | * Get all application URLs. |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | 18 | public function urls() |
|
51 | |||
52 | /** |
||
53 | * Get the root URL for the application identifier. |
||
54 | * |
||
55 | * @param string $app |
||
56 | * @return string |
||
57 | */ |
||
58 | 6 | public function root($app = '') |
|
63 | |||
64 | /** |
||
65 | * Get the URL domain for the application identifier. |
||
66 | * |
||
67 | * @param string $app |
||
68 | * @return string |
||
69 | */ |
||
70 | 2 | public function domain($app = '') |
|
74 | |||
75 | /** |
||
76 | * Get the URL prefix for the application identifier. |
||
77 | * |
||
78 | * @param string $app |
||
79 | * @return string |
||
80 | */ |
||
81 | 2 | public function prefix($app = '') |
|
85 | |||
86 | /** |
||
87 | * Get or check the current application identifier. |
||
88 | * |
||
89 | * @return string|bool |
||
90 | */ |
||
91 | 11 | public function id() |
|
103 | |||
104 | /** |
||
105 | * Get the application identifier for the given URL. |
||
106 | * |
||
107 | * @param string $url |
||
108 | * @return string|null |
||
109 | */ |
||
110 | 12 | public function idForUrl($url) |
|
111 | { |
||
112 | 12 | return collect($this->urls()) |
|
113 | 12 | ->filter(function ($root) use ($url) { |
|
114 | 12 | return $this->urlHasRoot($url, $root); |
|
115 | 12 | }) |
|
116 | 12 | ->sortByDesc(function ($root) { |
|
117 | 11 | return strlen($root); |
|
118 | 12 | }) |
|
119 | 12 | ->keys() |
|
120 | 12 | ->first(); |
|
121 | } |
||
122 | |||
123 | /** |
||
124 | * Refresh the current application identifier. |
||
125 | * |
||
126 | * @return $this |
||
127 | */ |
||
128 | 3 | public function refreshId() |
|
134 | |||
135 | /** |
||
136 | * Determine if a URL has the given root URL. |
||
137 | * |
||
138 | * @param string $url |
||
139 | * @param string $root |
||
140 | * @param bool $strict |
||
141 | * @return bool |
||
142 | */ |
||
143 | 12 | protected function urlHasRoot($url, $root, $strict = false) |
|
152 | |||
153 | /** |
||
154 | * Remove scheme for a URL. |
||
155 | * |
||
156 | * @param string $url |
||
157 | * @return string |
||
158 | */ |
||
159 | 12 | protected function removeScheme($url) |
|
163 | |||
164 | /** |
||
165 | * Generate an absolute URL to a path for the given application identifier. |
||
166 | * |
||
167 | * @param string $app |
||
168 | * @param string $path |
||
169 | * @param mixed $parameters |
||
170 | * @return string |
||
171 | */ |
||
172 | 1 | public function url($app = '', $path = '', $parameters = []) |
|
179 | |||
180 | /** |
||
181 | * Generate the URL to an application asset. |
||
182 | * |
||
183 | * @param string $path |
||
184 | * @param bool|null $secure |
||
185 | * @return string |
||
186 | */ |
||
187 | 1 | public function asset($path, $secure = null) |
|
191 | |||
192 | /** |
||
193 | * Return the remainder of a string after a given value. |
||
194 | * |
||
195 | * @param string $subject |
||
196 | * @param string $search |
||
197 | * @return string |
||
198 | */ |
||
199 | 1 | protected function stringAfter($subject, $search) |
|
203 | |||
204 | /** |
||
205 | * Register routes for each application. |
||
206 | * |
||
207 | * You may call this method in the `map` method of your `RouteServiceProvider`. |
||
208 | * |
||
209 | * @param array $attributes |
||
210 | * @return void |
||
211 | */ |
||
212 | 1 | public function routes(array $attributes = []) |
|
227 | |||
228 | /** |
||
229 | * Get route group attributes for the given application. |
||
230 | * |
||
231 | * @param string $app |
||
232 | * @param array $attributes |
||
233 | * @return array |
||
234 | */ |
||
235 | 1 | protected function getRouteGroupAttributes($app, array $attributes = []) |
|
246 | |||
247 | /** |
||
248 | * Get the root controller namespace for the given application. |
||
249 | * |
||
250 | * @param string $app |
||
251 | * @return string |
||
252 | */ |
||
253 | 1 | protected function getRootControllerNamespace($app) |
|
260 | } |
||
261 |