1 | <?php |
||
8 | class Apps |
||
9 | { |
||
10 | /** |
||
11 | * The container instance. |
||
12 | * |
||
13 | * @var \Illuminate\Contracts\Container\Container |
||
14 | */ |
||
15 | protected $container; |
||
16 | |||
17 | /** |
||
18 | * The current application identifier. |
||
19 | * |
||
20 | * @var string|false |
||
21 | */ |
||
22 | protected $id = false; |
||
23 | |||
24 | /** |
||
25 | * Create a new Apps instance. |
||
26 | * |
||
27 | * @param \Illuminate\Contracts\Container\Container $container |
||
28 | */ |
||
29 | 7 | public function __construct(Container $container) |
|
30 | { |
||
31 | 7 | $this->container = $container; |
|
32 | |||
33 | $this->container->rebinding('request', function () { |
||
34 | 1 | $this->refreshId(); |
|
35 | 7 | }); |
|
36 | 7 | } |
|
37 | |||
38 | /** |
||
39 | * Get or check the current application identifier. |
||
40 | * |
||
41 | * @return string|bool |
||
42 | */ |
||
43 | 3 | public function id() |
|
44 | { |
||
45 | 3 | if ($this->id === false) { |
|
46 | 3 | $this->id = $this->idForUrl($this->container['request']->getUri()); |
|
47 | } |
||
48 | |||
49 | 3 | if (func_num_args() > 0) { |
|
50 | 1 | return in_array($this->id, is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args()); |
|
51 | } |
||
52 | |||
53 | 2 | return $this->id; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * Refresh the current application identifier. |
||
58 | * |
||
59 | * @return $this |
||
60 | */ |
||
61 | 2 | public function refreshId() |
|
67 | |||
68 | /** |
||
69 | * Get application identifier for the given URL. |
||
70 | * |
||
71 | * @param string $url |
||
72 | * @return string |
||
73 | */ |
||
74 | 4 | public function idForUrl($url) |
|
86 | |||
87 | /** |
||
88 | * Determine if an URL has the given root URL. |
||
89 | * |
||
90 | * @param string $url |
||
91 | * @param string $root |
||
92 | * @param bool $strict |
||
93 | * @return bool |
||
94 | */ |
||
95 | 4 | protected function urlHasRoot($url, $root, $strict = false) |
|
104 | |||
105 | /** |
||
106 | * Generate an absolute URL to the given path. |
||
107 | * |
||
108 | * @param string $path |
||
109 | * @param mixed $query |
||
110 | * @param mixed $appId |
||
111 | * @return string |
||
112 | */ |
||
113 | 1 | public function url($path = '', $query = [], $appId = '') |
|
134 | } |
||
135 |