1 | <?php |
||
9 | class Apps |
||
10 | { |
||
11 | /** |
||
12 | * The container instance. |
||
13 | * |
||
14 | * @var \Illuminate\Contracts\Container\Container |
||
15 | */ |
||
16 | protected $container; |
||
17 | |||
18 | /** |
||
19 | * The current application identifier. |
||
20 | * |
||
21 | * @var string|false |
||
22 | */ |
||
23 | protected $id = false; |
||
24 | |||
25 | /** |
||
26 | * Create a new Apps instance. |
||
27 | * |
||
28 | * @param \Illuminate\Contracts\Container\Container $container |
||
29 | */ |
||
30 | 10 | public function __construct(Container $container) |
|
38 | |||
39 | /** |
||
40 | * Get or check the current application identifier. |
||
41 | * |
||
42 | * @return string|bool |
||
43 | */ |
||
44 | 3 | public function id() |
|
56 | |||
57 | /** |
||
58 | * Refresh the current application identifier. |
||
59 | * |
||
60 | * @return $this |
||
61 | */ |
||
62 | 2 | public function refreshId() |
|
68 | |||
69 | /** |
||
70 | * Get application identifier for the given URL. |
||
71 | * |
||
72 | * @param string $url |
||
73 | * @return string |
||
74 | */ |
||
75 | 4 | public function idForUrl($url) |
|
76 | { |
||
77 | 4 | return collect($this->container['config']['apps.url']) |
|
78 | ->filter(function ($root) use ($url) { |
||
79 | 4 | return $this->urlHasRoot($url, $root); |
|
80 | 4 | }) |
|
81 | ->sortByDesc(function ($root) { |
||
82 | 4 | return strlen($root); |
|
83 | 4 | }) |
|
84 | 4 | ->keys() |
|
85 | 4 | ->first(); |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Determine if an URL has the given root URL. |
||
90 | * |
||
91 | * @param string $url |
||
92 | * @param string $root |
||
93 | * @param bool $strict |
||
94 | * @return bool |
||
95 | */ |
||
96 | 4 | protected function urlHasRoot($url, $root, $strict = false) |
|
105 | |||
106 | /** |
||
107 | * Remove scheme for an URL. |
||
108 | * |
||
109 | * @param string $url |
||
110 | * @return string |
||
111 | */ |
||
112 | 4 | protected function removeScheme($url) |
|
116 | |||
117 | /** |
||
118 | * Get the root URL for the given application identifier. |
||
119 | * |
||
120 | * @param string $appId |
||
121 | * @return string |
||
122 | */ |
||
123 | 4 | public function root($appId = '') |
|
128 | |||
129 | /** |
||
130 | * Get the domain for the given application identifier. |
||
131 | * |
||
132 | * @param string $appId |
||
133 | * @return string |
||
134 | */ |
||
135 | 1 | public function domain($appId = '') |
|
139 | |||
140 | /** |
||
141 | * Get the URL prefix for the given application identifier. |
||
142 | * |
||
143 | * @param string $appId |
||
144 | * @return string |
||
145 | */ |
||
146 | 1 | public function prefix($appId = '') |
|
150 | |||
151 | /** |
||
152 | * Generate an absolute URL to a path for the given application identifier. |
||
153 | * |
||
154 | * @param string $appId |
||
155 | * @param string $path |
||
156 | * @param mixed $extra |
||
157 | * @return string |
||
158 | */ |
||
159 | 1 | public function url($appId = '', $path = '', $extra = []) |
|
166 | |||
167 | /** |
||
168 | * Return the remainder of a string after a given value. |
||
169 | * |
||
170 | * @param string $subject |
||
171 | * @param string $search |
||
172 | * @return string |
||
173 | */ |
||
174 | 1 | protected function stringAfter($subject, $search) |
|
178 | |||
179 | /** |
||
180 | * Register routes for each sub application. |
||
181 | * |
||
182 | * @param array $attributes |
||
183 | * @return void |
||
184 | */ |
||
185 | public function routes(array $attributes = []) |
||
200 | |||
201 | /** |
||
202 | * Get route group attributes for the given application identifier. |
||
203 | * |
||
204 | * @param string $appId |
||
205 | * @param array $attributes |
||
206 | * @return array |
||
207 | */ |
||
208 | protected function getRouteGroupAttributes($appId, array $attributes = []) |
||
225 | |||
226 | /** |
||
227 | * Get the root controller namespace. |
||
228 | * |
||
229 | * @return string |
||
230 | */ |
||
231 | protected function getRootControllerNamespace() |
||
239 | } |
||
240 |