private function setSiteDomain() { $hostInfo = str_replace('www.', '', $this->hostInfo); $host = parse_url($hostInfo, PHP_URL_HOST); $hostNames = explode(".", $host); $count = count($hostNames); if ($count > 4) { throw new InvalidConfigException( 'Unsupported URL format. host address cannot consist of more than 4 parts. e.g. eng.uni.ac.ir' ); } elseif ($count == 4) { $domain = $this->extractDomainFrom4PartsHostName($hostNames); } elseif ($count == 3) { $domain = $this->extractDomainFrom3PartsHostName($hostNames); } elseif ($count == 2) { $domain = implode('.', $hostNames);
Custom rules can be set in each module\'s config file.' ); } $this->redirectToSecureIfNeeded(); $this->subdomainAsPrefix = (int) Yii::$app->setting->get('website.subdomainIsEnabled'); if ($this->subdomainAsPrefix) { $this->setSiteDomain(); $this->setDefaultRulesForSubdomainAsPrefix(); } else { $this->setDefaultRulesForSubdomainAsDirectory(); } $this->mergeFileRules(); $this->mergeModulesRules();
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
$config = $this->resolveDependencies($config); if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten) $dependencies[count($dependencies) - 1] = $config; return $reflection->newInstanceArgs($dependencies); } $object = $reflection->newInstanceArgs($dependencies); foreach ($config as $name => $value) { $object->$name = $value; }
$class = $class->id; } if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
return static::$container->get($class, $params, $type); } if (isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } throw new InvalidConfigException('Object configuration must be an array containing a "class" or "__class" element.'); } private static $_logger;
if (isset($this->_definitions[$id])) { $definition = $this->_definitions[$id]; if (is_object($definition) && !$definition instanceof Closure) { return $this->_components[$id] = $definition; } return $this->_components[$id] = Yii::createObject($definition); } elseif ($throwException) { throw new InvalidConfigException("Unknown component ID: $id"); } return null; }
* Since version 2.0.13, if a component isn't defined in the module, it will be looked up in the parent module. * The parent module may be the application. */ public function get($id, $throwException = true) { if (!isset($this->module)) { return parent::get($id, $throwException); } $component = parent::get($id, false); if ($component === null) { $component = $this->module->get($id, $throwException); }
/** * Returns the URL manager for this application. * @return \yii\web\UrlManager the URL manager for this application. */ public function getUrlManager() { return $this->get('urlManager'); } /** * Returns the internationalization (i18n) component. * @return \yii\i18n\I18N the internationalization application component. */
* Resolves the current request into a route and the associated parameters. * @return array the first element is the route, and the second is the associated parameters. * @throws NotFoundHttpException if the request cannot be resolved. */ public function resolve() { $result = Yii::$app->getUrlManager()->parseRequest($this); if ($result !== false) { list($route, $params) = $result; if ($this->_queryParams === null) { $_GET = $params + $_GET; // preserve numeric keys } else { $this->_queryParams = $params + $this->_queryParams;
* @throws NotFoundHttpException if the requested route is invalid */ public function handleRequest($request) { if (empty($this->catchAll)) { try { list($route, $params) = $request->resolve(); } catch (UrlNormalizerRedirectException $e) { $url = $e->url; if (is_array($url)) { if (isset($url[0])) { // ensure the route is absolute $url[0] = '/' . ltrim($url[0], '/');
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); $configFolder = 'frontend'; $config = require(__DIR__ . '/../config/merge-configs.php'); $application = new yii\web\Application($config); $application->run();