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
35 lines (29 loc) · 1014 Bytes
/
TenantFinder.php
File metadata and controls
35 lines (29 loc) · 1014 Bytes
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
<?php
namespace ProcessMaker\Multitenancy;
use Illuminate\Http\Request;
use Illuminate\Support\Env;
use Spatie\Multitenancy\Contracts\IsTenant;
use Spatie\Multitenancy\TenantFinder\DomainTenantFinder;
class TenantFinder extends DomainTenantFinder
{
public function findForRequest(Request $request): ?IsTenant
{
$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;
}
}