111 lines
2.8 KiB
PHP
111 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: shenyang
|
|
* Date: 2018/7/9
|
|
* Time: 下午9:40
|
|
*/
|
|
|
|
namespace app\framework\Http;
|
|
|
|
|
|
use app\common\facades\SiteSetting;
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Request extends \Illuminate\Http\Request
|
|
{
|
|
private $route;
|
|
/**
|
|
* @var bool
|
|
*/
|
|
private $isBackend;
|
|
|
|
public function isBackend()
|
|
{
|
|
if (!isset($this->isBackend)) {
|
|
if (config('app.framework') == 'platform') {
|
|
$this->isBackend = strpos(request()->getRequestUri(), config('app.isWeb')) !== false ? true : false;
|
|
} else {
|
|
$this->isBackend = strpos($_SERVER['PHP_SELF'], '/web/index.php') !== false ? true : false;
|
|
}
|
|
}
|
|
return $this->isBackend;
|
|
}
|
|
|
|
public function isShop()
|
|
{
|
|
return !$this->isPlugins();
|
|
}
|
|
|
|
public function isFrontend()
|
|
{
|
|
if (strpos(request()->getRequestUri(), '/addons/') !== false
|
|
&& strpos(request()->getRequestUri(), '/api.php') !== false
|
|
) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function isPayment()
|
|
{
|
|
return strpos($_SERVER['PHP_SELF'], '/payment/') > 0 ? true : false;
|
|
}
|
|
|
|
public function isPlugins()
|
|
{
|
|
return Str::startsWith(request('route'), 'plugin.');
|
|
}
|
|
|
|
public function isCron()
|
|
{
|
|
return strpos(request()->getRequestUri(), '/addons/') !== false &&
|
|
strpos(request()->getRequestUri(), '/cron.php') !== false;
|
|
}
|
|
|
|
/**
|
|
* 前后端强制https跳转app
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getScheme()
|
|
{
|
|
try {
|
|
if ((config('app.framework') == 'platform' && file_exists(base_path().'/bootstrap/install.lock'))
|
|
|| config('app.framework') != 'platform') {
|
|
if (SiteSetting::get('base.https')) {
|
|
return 'https';
|
|
}
|
|
}
|
|
} catch (QueryException $exception) {
|
|
\Log::error('getScheme error', $exception->getMessage());
|
|
}
|
|
return parent::getScheme();
|
|
}
|
|
|
|
public function getHost()
|
|
{
|
|
try {
|
|
if ((config('app.framework') == 'platform' && file_exists(base_path().'/bootstrap/install.lock'))
|
|
|| config('app.framework') != 'platform') {
|
|
if (parent::getHost() == 'localhost' && SiteSetting::get('base.host')) {
|
|
return SiteSetting::get('base.host');
|
|
}
|
|
}
|
|
} catch (QueryException $exception) {
|
|
\Log::error('getHost error', $exception->getMessage());
|
|
}
|
|
return parent::getHost(); // TODO: Change the autogenerated stub
|
|
}
|
|
|
|
public function setRoute($route)
|
|
{
|
|
$this->route = $route;
|
|
}
|
|
|
|
public function getRoute()
|
|
{
|
|
return $this->route;
|
|
}
|
|
} |