| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?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;
- }
- }
|