|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
-
-
-
- namespace common\components;
-
- use Yii;
- use yii\helpers\Url;
- use yii\base\InvalidConfigException;
- use yii\web\UrlManager ;
-
- class UrlManagerCommon extends UrlManager
- {
- public $subDomain;
- public $domainName;
-
- protected $_hostInfo;
-
- public function getProperDomain()
- {
- if ( ! isset($this->domainName) || empty($this->domainName) ) {
- throw new InvalidConfigException('Request requires a domain name to be configured!');
- }
-
- $subDomain = (isset($this->subDomain) && !empty($this->subDomain)) ? $this->subDomain : '';
- $domain = empty($subDomain) ? '' : $subDomain . '.';
- $domain .= $this->domainName;
-
- return $domain;
- }
-
- public function getHostInfo()
- {
- if ($this->_hostInfo === null)
- {
- $secure = Yii::$app->getRequest()->getIsSecureConnection();
- $http = $secure ? 'https' : 'http';
-
- if (isset($_SERVER['HTTP_HOST'])) {
- $this->_hostInfo = $http . '://' . $this->getProperDomain();
- } elseif (isset($_SERVER['SERVER_NAME'])) {
- $this->_hostInfo = $http . '://' . $this->getProperDomain();
- $port = $secure ? $this->getSecurePort() : $this->getPort();
-
- if (($port !== 80 && !$secure) || ($port !== 443 && $secure)) {
- $this->_hostInfo .= ':' . $port;
- }
- }
- }
- return $this->_hostInfo;
- }
-
- }
|