forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTenantFinder.php
More file actions
44 lines (36 loc) · 1.19 KB
/
TenantFinder.php
File metadata and controls
44 lines (36 loc) · 1.19 KB
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
<?php
namespace ProcessMaker\Multitenancy;
use Illuminate\Http\Request;
use Illuminate\Support\Env;
use ProcessMaker\Multitenancy\Tenant;
use Spatie\Multitenancy\Contracts\IsTenant;
use Spatie\Multitenancy\TenantFinder\DomainTenantFinder;
class TenantFinder extends DomainTenantFinder
{
public function findForRequest(Request $request): ?IsTenant
{
if (!config('app.multitenancy')) {
return null;
}
if ($tenant = Tenant::fromBootstrapper()) {
return $tenant;
}
$tenant = null;
$message = null;
/**
* This could be a console command disguised as an http request (APP_RUNNING_IN_CONSOLE=false)
* Check if we have a TENANT env variable set.
* See ProcessMakerServiceProvider::setCurrentTenantForConsoleCommands() for non-disguised console commands
*/
if (Env::get('TENANT')) {
$tenant = app(IsTenant::class)::findOrFail(Env::get('TENANT'));
}
if (!$tenant) {
try {
$tenant = parent::findForRequest($request);
} catch (\Illuminate\Database\QueryException $_e) {
}
}
return $tenant;
}
}