You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.8 KiB
78 lines
1.8 KiB
5 years ago
|
<?php
|
||
|
|
||
|
namespace App\CorePackages\VirtualActivity;
|
||
|
|
||
|
use App\CorePackages\VirtualActivity\Exceptions\VirtualActivityNotFoundException;
|
||
|
use App\CorePackages\VirtualActivity\Exceptions\SiteNotFoundException;
|
||
|
use App\Site;
|
||
|
use App\Business;
|
||
|
|
||
|
class VirtualActivityFinder
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* .
|
||
|
*
|
||
|
* @var array
|
||
|
*/
|
||
|
protected static $mainDomains = [
|
||
|
'willamall.com',
|
||
|
'willaengine',
|
||
|
'willadevelop.ir',
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* finds business object based on "url" or "logged_in user".
|
||
|
*
|
||
|
* @return Business
|
||
|
*/
|
||
|
public static function fetch() {
|
||
|
|
||
|
|
||
|
$domain = static::findSiteName(request()->root());
|
||
|
|
||
|
$site = Site::where('domain', $domain)->first();
|
||
|
|
||
|
if ($site) {
|
||
|
|
||
|
return $site->user_template->business;
|
||
|
|
||
|
} elseif (in_array($domain, static::$mainDomains)) {
|
||
|
if ( \AuthFinder::check() && \AuthFinder::user()->last_used_business !== 0) {
|
||
|
return Business::findOrFail(\AuthFinder::user()->last_used_business);
|
||
|
}
|
||
|
|
||
|
throw new VirtualActivityNotFoundException('Business Not Found');
|
||
|
}
|
||
|
|
||
|
throw new SiteNotFoundException('Site Not Found');
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* finds site name based on specified url address.
|
||
|
*
|
||
|
* @param string $domain
|
||
|
* @return Business
|
||
|
*/
|
||
|
public static function findSiteName($domain) {
|
||
|
|
||
|
$array = explode('.', parse_url($domain, PHP_URL_HOST));
|
||
|
if (count($array) == 4) {
|
||
|
$domain = $array[1];
|
||
|
} elseif (count($array) == 3) {
|
||
|
if ($array[0] === 'www') {
|
||
|
$domain = $array[1] . '.' . $array[2];
|
||
|
} else {
|
||
|
$domain = $array[0];
|
||
|
}
|
||
|
} elseif (count($array) == 2) {
|
||
|
$domain = $array[0] . '.' . $array[1];
|
||
|
}
|
||
|
return $domain;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|