-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhelpers.php
122 lines (102 loc) · 2.65 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
use App\Containers\Larabeans\Tenanter\Contracts\Host;
use App\Containers\Larabeans\Tenanter\Contracts\Tenant;
use App\Containers\Larabeans\Tenanter\Contracts\Domain;
use App\Containers\Larabeans\Tenanter\Tenancy;
if (! function_exists('tenancy')) {
/** @return Tenancy */
function tenancy()
{
return app(Tenancy::class);
}
}
if (! function_exists('tenancyConfig')) {
/** @return Tenancy */
function tenancyConfig($attr)
{
return app(Tenancy::class)->config($attr);
}
}
if (! function_exists('host')) {
/**
* Get a key from the current host's storage.
*
* @param string|null $key
* @return Host|null|mixed
*/
function host($key = null)
{
if (! app()->bound(Host::class)) {
return;
}
if (is_null($key)) {
return app(Host::class);
}
return optional(app(Host::class))->getAttribute($key) ?? null;
}
}
if (! function_exists('tenant')) {
/**
* Get a key from the current tenant's storage.
*
* @param string|null $key
* @return Tenant|null|mixed
*/
function tenant($key = null)
{
if (! app()->bound(Tenant::class)) {
return;
}
if (is_null($key)) {
return app(Tenant::class);
}
return optional(app(Tenant::class))->getAttribute($key) ?? null;
}
}
if (! function_exists('domain')) {
/**
* Get a key from the current host's storage.
*
* @param string|null $key
* @return Domain|null|mixed
*/
function domain($key = null)
{
if (! app()->bound(Domain::class)) {
return;
}
if (is_null($key)) {
return app(Domain::class);
}
return optional(app(Domain::class))->getAttribute($key) ?? null;
}
}
if (! function_exists('tenant_asset')) {
/** @return string */
function tenant_asset($asset)
{
return app('url')->asset($asset);
}
}
if (! function_exists('global_asset')) {
function global_asset($asset)
{
return app('globalUrl')->asset($asset);
}
}
if (! function_exists('global_cache')) {
function global_cache()
{
return app('globalCache');
}
}
if (! function_exists('tenant_route')) {
function tenant_route(string $domain, $route, $parameters = [], $absolute = true)
{
// replace first occurance of hostname fragment with $domain
$url = route($route, $parameters, $absolute);
$hostname = parse_url($url, PHP_URL_HOST);
$position = strpos($url, $hostname);
return substr_replace($url, $domain, $position, strlen($hostname));
}
}