getPathInfo() public méthode

A path info refers to the part that is after the entry script and before the question mark (query string). The starting and ending slashes are both removed.
public getPathInfo ( ) : string
Résultat string part of the request URL that is after the entry script and before the question mark. Note, the returned path info is already URL-decoded.
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     foreach ($this->skip as $item) {
         if (strpos($request->getPathInfo(), $item) !== false) {
             return false;
         }
     }
     $path = $request->getPathInfo();
     $redirect = false;
     // Слэш в конце
     if (substr($path, -1) == '/') {
         $redirect = true;
         $path = trim($path, '/');
     }
     // Двойной слэш
     if (strpos($path, '//') !== false) {
         $redirect = true;
         $path = str_replace('//', '/', $path);
     }
     // Символы в верхнем регистре
     if (($tmpUrl = strtolower($path)) !== $path) {
         $redirect = true;
         $path = $tmpUrl;
     }
     if ($redirect) {
         Yii::$app->response->redirect([$path], 301);
         Yii::$app->end();
     }
     return false;
 }
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     foreach ($this->skip as $item) {
         if (strpos($request->getPathInfo(), $item) !== false) {
             return false;
         }
     }
     /** @var UrlRoute $model */
     $model = $this->modelClass;
     $model = $model::find()->andWhere(['path' => $request->getPathInfo()])->one();
     if ($model == null) {
         return false;
     }
     if ($model->checkAction($model::ACTION_INDEX)) {
         return [$model->getRoute()];
     } elseif ($model->checkAction($model::ACTION_VIEW)) {
         return [$model->getRoute(), ['id' => $model->object_id]];
     } elseif ($model->checkAction($model::ACTION_REDIRECT)) {
         $url = $model->url_to;
         if (strpos($url, 'http://') === false) {
             $url = [$url];
         }
         Yii::$app->response->redirect($url, $model->http_code);
         Yii::$app->end();
     }
     return false;
 }
Exemple #3
0
 /**
  * Parses the given request and returns the corresponding route and parameters.
  *
  * @param UrlManager $manager the URL manager
  * @param Request    $request the request component
  *
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     echo '<pre>==== BeeUrlRule ===<br>';
     print_r('PathInfo = ' . $request->getPathInfo());
     echo '<br>';
     print_r('Url = ' . $request->getUrl());
     echo '<br>======================</pre>';
     $items = Yii::$app->getSiteMenu()->getMenu();
     // Parse SEF URL
     if (Yii::$app->urlManager->enablePrettyUrl == TRUE) {
         $route = $request->getPathInfo();
         /*
          *  Пошаговый парсинг меню
          *  Последне найденный записывается в переменную $found
          */
         $found = null;
         foreach ($items as $item) {
             if ($item->path && BeeString::strpos($route, $item->path) === 0) {
                 // Exact route match. We can break iteration because exact item was found.
                 if ($item->path == $route) {
                     $found = $item;
                     break;
                 }
                 // Partial route match. Item with highest level takes priority.
                 if (!$found || $found->level < $item->level) {
                     $found = $item;
                 }
             }
         }
         /*
          * Если мы нашли конечный пункт меню и его адрес полностью собпадает,
          * то формируем и возвращаем ссылку на этот пункт меню
          * иначе берем компонент в @found и продолжаем поиск уже по этому компоненту.
          */
         if (BeeString::strpos($route, $found->path) === 0) {
             $extAction = $found->query[0];
             // site/index
             $url = ['path' => $found->query['path'], 'id' => $found->query['id']];
             return [$extAction, $url];
         } else {
             echo '<pre>';
             print_r('------------------- Еще не все распарсил -------------------');
             echo '</pre>';
         }
         //echo '<br><br><br><pre>';
         //print_r($found);
         //echo '</pre><br><br><br>';
         echo '<br><pre>Сделать парсинг для страниц, отсутствующих в меню';
         echo '<br>======================</pre>';
     } else {
         // Parse RAW URL
         return FALSE;
     }
     echo '<pre><<< Стандартный парсино Yii >>></pre>';
     return FALSE;
     //return ['site/about', []];
 }
Exemple #4
0
 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     if ($this->mode === self::CREATION_ONLY) {
         return false;
     }
     if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) {
         return false;
     }
     $pathInfo = $request->getPathInfo();
     if ($this->host !== null) {
         $pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo);
     }
     $params = $request->getQueryParams();
     $suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
     $treeNode = null;
     $originalDir = $pathInfo;
     if ($suffix) {
         $originalDir = substr($pathInfo, 0, strlen($pathInfo) - strlen($suffix));
     }
     $dependency = new TagDependency(['tags' => [(new Tree())->getTableCacheTag()]]);
     if (!$pathInfo) {
         $treeNode = Tree::getDb()->cache(function ($db) {
             return Tree::find()->where(["site_code" => \Yii::$app->cms->site->code, "level" => 0])->one();
         }, null, $dependency);
     } else {
         $treeNode = Tree::find()->where(["dir" => $originalDir, "site_code" => \Yii::$app->cms->site->code])->one();
     }
     if ($treeNode) {
         \Yii::$app->cms->setCurrentTree($treeNode);
         $params['id'] = $treeNode->id;
         return ['cms/tree/view', $params];
     } else {
         return false;
     }
 }
 /**
  * 获取响应的格式
  * @return string
  */
 protected function getFormat()
 {
     if ('' != ($extension = pathinfo($this->request->getPathInfo(), PATHINFO_EXTENSION))) {
         $this->format = strtolower($extension);
     }
     return $this->format == '' ? 'html' : $this->format;
 }
 /**
  * Parses the URL and sets the language accordingly
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($request)
 {
     if ($this->enablePrettyUrl) {
         $pathInfo = $request->getPathInfo();
         $language = explode('/', $pathInfo)[0];
         $locale = ArrayHelper::getValue($this->aliases, $language, $language);
         if (in_array($language, $this->languages)) {
             $request->setPathInfo(substr_replace($pathInfo, '', 0, strlen($language) + 1));
             Yii::$app->language = $locale;
             static::$currentLanguage = $language;
         }
     } else {
         $params = $request->getQueryParams();
         $route = isset($params[$this->routeParam]) ? $params[$this->routeParam] : '';
         if (is_array($route)) {
             $route = '';
         }
         $language = explode('/', $route)[0];
         $locale = ArrayHelper::getValue($this->aliases, $language, $language);
         if (in_array($language, $this->languages)) {
             $route = substr_replace($route, '', 0, strlen($language) + 1);
             $params[$this->routeParam] = $route;
             $request->setQueryParams($params);
             Yii::$app->language = $locale;
             static::$currentLanguage = $language;
         }
     }
     return parent::parseRequest($request);
 }
Exemple #7
0
 /**
  *
  * @param \yii\web\UrlManager $manager            
  * @param \yii\web\Request $request            
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $rule = $this->getRuleByPattern($request->getPathInfo(), null);
     if ($rule) {
         $params = [];
         parse_str($rule->defaults, $params);
         return [$rule->route, $params];
     }
     return false;
 }
 public function getPathInfo()
 {
     // Добавить кэш $pathInfo (не забыть про setPathInfo)
     $pathInfo = parent::getPathInfo();
     $pattern = Languages::all()->pattern();
     if (preg_match("/^({$pattern})\\/(.*)/", $pathInfo, $arr)) {
         $this->lang_url = $arr[1];
         $pathInfo = $arr[count($arr) - 1];
     }
     return $pathInfo;
 }
Exemple #9
0
 /**
  * @param \yii\web\Request $request
  * @return string
  */
 public function getRouteFromSlug($request)
 {
     $_route = $request->getPathInfo();
     $_params = $request->get();
     $dbRoute = $this->getRouteFromCacheOrWriteCacheThenRead($_route, $_params);
     if (is_object($dbRoute) && $dbRoute->hasAttribute('redirect')) {
         if ($dbRoute->getAttribute('redirect')) {
             Yii::$app->response->redirect([$dbRoute->slug], $dbRoute->getAttribute('redirect_code'));
         }
     }
     return $_route;
 }
Exemple #10
0
 /**
  * Parse request
  *
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  *
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $url = preg_replace('#/$#', '', $pathInfo);
     $page = (new CmsModel())->findPage($url);
     if (!empty($page)) {
         $params['pageAlias'] = $url;
         $params['pageId'] = $page->id;
         return [$this->route, $params];
     }
     return parent::parseRequest($manager, $request);
 }
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     // If it's base url - call main page
     if ($request->getPathInfo() === '') {
         $mainPage = $this->getMainPage();
         if ($mainPage !== false) {
             Singleton::setData('content_template_id', $mainPage['content_template_id']);
             if ($mainPage['type'] == ContentPage::TYPE_TEXT) {
                 return ['/content/default/view', ['slug' => $mainPage['slug']]];
             } elseif ($mainPage['type'] == ContentPage::TYPE_INTERNAL_LINK) {
                 return ['/' . ltrim($mainPage['slug'], '/'), []];
             }
         }
     }
     $path = rtrim($request->getPathInfo(), '/');
     $parts = explode('/', $path);
     $languagePart = null;
     // Multilingual support - remove language from parts
     if (isset(Yii::$app->params['mlConfig']['languages'])) {
         if (array_key_exists($parts[0], Yii::$app->params['mlConfig']['languages'])) {
             $languagePart = array_shift($parts);
         }
     }
     $slug = count($parts) == 1 && $parts[0] != '' ? $parts[0] : end($parts);
     if (isset($this->getAllPages()[$slug])) {
         if (isset($this->getAllPages()[$slug])) {
             $page = $this->getAllPages()[$slug];
             Singleton::setData('content_template_id', $page['content_template_id']);
             return ['content/default/view', ['slug' => $slug, '_language' => $languagePart]];
         }
     } elseif (count($parts) > 1) {
         $slug = implode('/', $parts);
         if (isset($this->getAllPages()[$slug])) {
             $page = $this->getAllPages()[$slug];
             Singleton::setData('content_template_id', $page['content_template_id']);
         }
     }
     return false;
     // this rule does not apply
 }
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param \yii\web\UrlManager $manager the URL manager
  * @param \yii\web\Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     $this->initPatrones();
     $pathInfo = $request->getPathInfo();
     //vendedor
     if ($this->verificaRuta($this->patrones[self::P_VENDEDOR], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_VENDEDOR], $pathInfo);
         return [$this->ruta[self::P_VENDEDOR], $parametros];
     }
     //profesional
     if ($this->verificaRuta($this->patrones[self::P_PROFESIONAL], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_PROFESIONAL], $pathInfo);
         return [$this->ruta[self::P_PROFESIONAL], $parametros];
     }
     //categoria
     if ($this->verificaRuta($this->patrones[self::P_CATEGORIAS], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_CATEGORIAS], $pathInfo);
         //            echo '<pre>';print_r([__LINE__, __METHOD__,$pathInfo,$this->patrones[self::P_CATEGORIAS]]);die();
         //registrar click
         //            if(Yii::$app->request->getBodyParam('hc') == 7 ){
         //                Yii::$app->visitas->registrarClick($parametros['categoria'], 'C');
         //            }
         //registro de impresion de la categoria
         //            Yii::$app->visitas->registrarImpresion($parametros['categoria'], 'C');
         return [$this->ruta[self::P_CATEGORIAS], $parametros];
     }
     //categoria-provincia
     if ($this->verificaRuta($this->patrones[self::P_CATEGORIA_PROVINCIA], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_CATEGORIA_PROVINCIA], $pathInfo);
         //registro de impresion de la categoria
         return [$this->ruta[self::P_CATEGORIA_PROVINCIA], $parametros];
     }
     //detalle articulo
     //municipio/articulo
     if ($this->verificaRuta($this->patrones[self::P_MUNICIPIO_DESCUENTO], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_MUNICIPIO_DESCUENTO], $pathInfo);
         //registrar click
         //            if(Yii::$app->request->getBodyParam('hc') == 7 ){
         //                Yii::$app->visitas->registrarClick($parametros['articulo'], 'A');
         //            }
         //registro de impresion de la categoria
         //            Yii::$app->visitas->registrarImpresion($parametros['articulo'], 'A');
         return [$this->ruta[self::P_MUNICIPIO_DESCUENTO], $parametros];
     }
     //provincia
     if ($this->verificaRuta($this->patrones[self::P_PROVINCIA], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_PROVINCIA], $pathInfo);
         return [$this->ruta[self::P_PROVINCIA], $parametros];
     }
     return false;
 }
Exemple #13
0
 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $params = $request->getQueryParams();
     $sourceOriginalFile = File::object($pathInfo);
     $extension = $sourceOriginalFile->getExtension();
     if (!$extension) {
         return false;
     }
     if (!in_array(StringHelper::strtolower($extension), (array) \Yii::$app->imaging->extensions)) {
         return false;
     }
     return ['cms/imaging/process', $params];
 }
Exemple #14
0
 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $params = $request->getQueryParams();
     $sourceOriginalFile = File::object($pathInfo);
     $extension = $sourceOriginalFile->getExtension();
     if (!$extension) {
         return false;
     }
     if (Validate::validate(new AllowExtension(), $extension)->isInvalid()) {
         return false;
     }
     return ['cms/imaging/process', $params];
 }
 /**
  * Redirect to the current URL with given language code applied
  *
  * @param string $language the language code to add. Can also be empty to not add any language code.
  */
 protected function redirectToLanguage($language)
 {
     // Examples:
     // 1) /baseurl/index.php/some/page?q=foo
     // 2) /baseurl/some/page?q=foo
     // 3)
     // 4) /some/page?q=foo
     if ($this->showScriptName) {
         // 1) /baseurl/index.php
         // 2) /baseurl/index.php
         // 3) /index.php
         // 4) /index.php
         $redirectUrl = $this->_request->getScriptUrl();
     } else {
         // 1) /baseurl
         // 2) /baseurl
         // 3)
         // 4)
         $redirectUrl = $this->_request->getBaseUrl();
     }
     if ($language) {
         $redirectUrl .= '/' . $language;
     }
     // 1) some/page
     // 2) some/page
     // 3)
     // 4) some/page
     $pathInfo = $this->_request->getPathInfo();
     if ($pathInfo) {
         $redirectUrl .= '/' . $pathInfo;
     }
     if ($redirectUrl === '') {
         $redirectUrl = '/';
     }
     // 1) q=foo
     // 2) q=foo
     // 3)
     // 4) q=foo
     $queryString = $this->_request->getQueryString();
     if ($queryString) {
         $redirectUrl .= '?' . $queryString;
     }
     Yii::$app->getResponse()->redirect($redirectUrl);
     if (YII_ENV_TEST) {
         throw new \yii\base\Exception(\yii\helpers\Url::to($redirectUrl));
     } else {
         Yii::$app->end();
     }
 }
 /**
  * Parse request
  *
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  *
  * @return boolean
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     // get path without '/' in end
     $url = preg_replace("#/\$#", "", $pathInfo);
     // find page by url in db
     $page = (new CmsModel())->findPage($url);
     // redirect to page
     if (!is_null($page)) {
         $params['pageAlias'] = $url;
         $params['pageId'] = $page->id;
         return [$this->route, $params];
     }
     return parent::parseRequest($manager, $request);
 }
Exemple #17
0
 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $params = $request->getQueryParams();
     $treeNode = null;
     if (!$pathInfo) {
         return $this->_go();
     }
     //Если урл преобразован, редирректим по новой
     $pathInfoNormal = $this->_normalizeDir($pathInfo);
     if ($pathInfo != $pathInfoNormal) {
         //\Yii::$app->response->redirect(DIRECTORY_SEPARATOR . $pathInfoNormal . ($params ? '?' . http_build_query($params) : '') );
     }
     return $this->_go($pathInfoNormal);
 }
Exemple #18
0
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|bool the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  * @throws NotFoundHttpException
  */
 public function parseRequest($manager, $request)
 {
     $this->currentLanguage = Language::getCurrent();
     $this->pathInfo = $request->getPathInfo();
     if ($this->pathInfo == $this->albumsRoute) {
         if ($this->disableDefault) {
             throw new NotFoundHttpException();
         }
         if (!empty($request->getQueryParams()['id'])) {
             $id = $request->getQueryParams()['id'];
             $album = GalleryAlbum::findOne($id);
             if (!$album) {
                 return false;
             }
             $translation = $album->getTranslation($this->currentLanguage->id);
             if ($translation) {
                 if (!empty($translation->seoUrl)) {
                     throw new NotFoundHttpException();
                 }
             }
         }
     }
     if (!empty($this->prefix)) {
         if (strpos($this->pathInfo, $this->prefix) === 0) {
             $this->pathInfo = substr($this->pathInfo, strlen($this->prefix));
         } else {
             return false;
         }
     }
     $this->initRoutes($this->pathInfo);
     if (!empty($this->prefix) && $this->routesCount == 1) {
         return [$this->albumsRoute, []];
     } else {
         if ($this->routesCount == 2) {
             $seoUrl = $this->routes[1];
             /* @var SeoData $seoData */
             $seoData = SeoData::find()->where(['entity_name' => GalleryAlbumTranslation::className(), 'seo_url' => $seoUrl])->one();
             if ($seoData) {
                 /* @var GalleryAlbum $album */
                 $album = GalleryAlbum::find()->joinWith('translations translation')->where(['translation.id' => $seoData->entity_id, 'translation.language_id' => $this->currentLanguage->id])->one();
                 if ($album) {
                     return [$this->albumsRoute, ['id' => $album->id]];
                 }
             }
         }
     }
     return false;
 }
Exemple #19
0
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|bool the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  * @throws NotFoundHttpException
  */
 public function parseRequest($manager, $request)
 {
     $this->currentLanguage = Language::getCurrent();
     $this->pathInfo = $request->getPathInfo();
     if ($this->pathInfo == $this->categoryRoute || $this->pathInfo == $this->productRoute) {
         Yii::$app->urlManager->language = $this->currentLanguage;
         if ($this->createUrl(Yii::$app->urlManager, $this->pathInfo, $request->getQueryParams())) {
             throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
         } else {
             if ($this->pathInfo == $this->productRoute && empty($request->getQueryParams()['id'])) {
                 throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
             }
         }
     }
     if (!empty($this->prefix)) {
         if (strpos($this->pathInfo, $this->prefix) === 0) {
             $this->pathInfo = substr($this->pathInfo, strlen($this->prefix));
         } else {
             return false;
         }
     }
     $this->initRoutes($this->pathInfo);
     if (!empty($this->prefix) && $this->routesCount == 1) {
         return [$this->categoryRoute, []];
     }
     $categoryId = null;
     for ($i = 1; $i < $this->routesCount; $i++) {
         if ($i === $this->routesCount - 1) {
             if ($product = $this->findProductBySeoUrl($this->routes[$i], $categoryId)) {
                 return ['/' . $this->productRoute, ['id' => $product->id]];
             } else {
                 if ($category = $this->findCategoryBySeoUrl($this->routes[$i], $categoryId)) {
                     return ['/' . $this->categoryRoute, ['id' => $category->id]];
                 } else {
                     return false;
                 }
             }
         } else {
             if ($category = $this->findCategoryBySeoUrl($this->routes[$i], $categoryId)) {
                 $categoryId = $category->id;
             } else {
                 return false;
             }
         }
     }
     return false;
 }
Exemple #20
0
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     /* @var $modelClass ActiveRecordInterface */
     if (empty($this->route)) {
         return false;
     }
     if (empty($this->modelClass) || !class_exists($this->modelClass)) {
         return false;
     } else {
         $modelClass = $this->modelClass;
     }
     $pathInfo = $request->getPathInfo();
     if (!empty($this->prefix)) {
         if (strpos($pathInfo, $this->prefix) === 0) {
             $pathInfo = substr($pathInfo, strlen($this->prefix));
         } else {
             return false;
         }
     }
     $routes = explode('/', $pathInfo);
     if (count($routes) == 1) {
         $seoData = SeoData::find()->where(['entity_name' => $modelClass, 'seo_url' => $routes[0]])->one();
         if (!empty($seoData)) {
             $condition = [];
             $condition[$modelClass::primaryKey()[0]] = $seoData->entity_id;
             if (!empty($this->condition)) {
                 foreach ($this->condition as $key => $value) {
                     if (is_callable($value)) {
                         $value = $value();
                     }
                     $condition[$key] = $value;
                 }
             }
             $model = $modelClass::find()->where($condition)->one();
             if (!empty($model)) {
                 $params = [];
                 if (!empty($this->params)) {
                     foreach ($this->params as $key => $param) {
                         $params[$key] = $model->{$param};
                     }
                 }
                 return [$this->route, $params];
             }
         }
     }
     return false;
 }
 public function getPathInfo()
 {
     $pathInfo = parent::getPathInfo();
     $pattern = LangHelper::pattern();
     if (preg_match("/^({$pattern})\\/(.*)/", $pathInfo, $arr)) {
         $this->lang_url = $arr[1];
         $pathInfo = $arr[count($arr) - 1];
     } else {
         if (isset($this->queryParams['x-language-url']) && LangHelper::getLanguageByParam('url', $this->queryParams['x-language-url'])) {
             // If enablePrettyUrl===false
             $this->lang_url = $this->queryParams['x-language-url'];
         } else {
             $this->lang_url = null;
         }
     }
     return $pathInfo;
 }
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     if (strpos($pathInfo, 'api') === 0) {
         return false;
     }
     return false;
     /*else {
           $params = $request->queryParams;
           if(isset($params['_escaped_fragment'])){
               return false;
           }
           return [
               'site/index', []
           ];
       }*/
 }
Exemple #23
0
 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $params = $request->getQueryParams();
     $firstPrefix = substr($pathInfo, 0, strlen($this->adminPrefix));
     if ($firstPrefix == $this->adminPrefix) {
         $route = str_replace($this->adminPrefix, "", $pathInfo);
         if (!$route || $route == "/") {
             $route = "admin/index";
         }
         $params[self::ADMIN_PARAM_NAME] = self::ADMIN_PARAM_VALUE;
         return [$route, $params];
         //return ["cms/admin-user", $params];
     }
     return false;
     // this rule does not apply
 }
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     if (preg_match('/^(\\w+)\\/(\\d+)\\/(\\w+)\\/([a-z0-9-_]+)/', $pathInfo, $matches)) {
         $module_name = $matches[1] . '-' . $matches[2];
         $controller = $matches[3];
         $action = $matches[4];
         return ["{$module_name}/{$controller}/{$action}", []];
     }
     if (preg_match('/^(\\w+)\\/(\\w+)\\/(\\d+)\\/(\\w+)\\/([a-z0-9-_]+)/', $pathInfo, $matches)) {
         $module_name = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
         $controller = $matches[4];
         $action = $matches[5];
         return ["{$module_name}/{$controller}/{$action}", []];
     }
     return false;
 }
Exemple #25
0
 /**
  * Parses the given request and returns the corresponding route and parameters.
  *
  * @param UrlManager $manager the URL manager
  * @param Request    $request the request component
  *
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     echo '<pre>--- BeeUrlRuleHome ---<br>';
     $menu = Yii::$app->getSiteMenu();
     $pathInfo = $request->getPathInfo();
     if (!empty($menu->getHomeID())) {
         if ($menu->getHome()->path == $pathInfo || $menu->getHome()->home == true && $pathInfo == '') {
             $extAction = $menu->getHome()->query[0];
             // site/index
             $url = ['path' => $menu->getHome()->query['path'], 'id' => $menu->getHome()->query['id']];
             echo '======================</pre>';
             return [$extAction, $url];
         }
     }
     echo '- - - - - - - - - - -</pre>';
     return FALSE;
 }
Exemple #26
0
 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $params = $request->getQueryParams();
     $treeNode = null;
     if (!$pathInfo) {
         return false;
     }
     if (!preg_match('/\\/(?<id>\\d+)\\-(?<code>\\S+)$/i', "/" . $pathInfo, $matches)) {
         return false;
     }
     //Если урл преобразован, редирректим по новой
     $pathInfoNormal = $this->_normalizeDir($pathInfo);
     if ($pathInfo != $pathInfoNormal) {
         //\Yii::$app->response->redirect(DIRECTORY_SEPARATOR . $pathInfoNormal . ($params ? '?' . http_build_query($params) : '') );
     }
     return ['cms/content-element/view', ['id' => $matches['id'], 'code' => $matches['code']]];
 }
Exemple #27
0
 /**
  * @todo should be rewritten soon.
  * @param \yii\web\Request $request
  */
 public function getResolvedPathInfo(\yii\web\Request $request)
 {
     $parts = explode('/', $request->getPathInfo());
     preg_match_all('/<(\\w+):?([^>]+)?>/', $this->pattern, $matches, PREG_SET_ORDER);
     $compositionKeys = [];
     foreach ($matches as $index => $match) {
         if (isset($parts[$index])) {
             $urlValue = $parts[$index];
             $rgx = $match[2];
             $param = $match[1];
             preg_match("/^{$rgx}\$/", $urlValue, $res);
             if (count($res) == 1) {
                 $compositionKeys[$param] = $urlValue;
                 $this->_resolvedValues[] = $parts[$index];
                 unset($parts[$index]);
             }
         }
     }
     if (count($compositionKeys) == 0) {
         $compositionKeys = $this->default;
     }
     $this->set($compositionKeys);
     return implode('/', $parts);
 }
Exemple #28
0
 /**
  * Parses the user request.
  * @param Request $request the request component
  * @return array|boolean the route and the associated parameters. The latter is always empty
  * if [[enablePrettyUrl]] is false. False is returned if the current request cannot be successfully parsed.
  */
 public function parseRequest($request)
 {
     if ($this->enablePrettyUrl) {
         $pathInfo = $request->getPathInfo();
         /* @var $rule UrlRule */
         foreach ($this->rules as $rule) {
             if (($result = $rule->parseRequest($this, $request)) !== false) {
                 return $result;
             }
         }
         if ($this->enableStrictParsing) {
             return false;
         }
         Yii::trace('No matching URL rules. Using default URL parsing logic.', __METHOD__);
         $suffix = (string) $this->suffix;
         if ($suffix !== '' && $pathInfo !== '') {
             $n = strlen($this->suffix);
             if (substr_compare($pathInfo, $this->suffix, -$n, $n) === 0) {
                 $pathInfo = substr($pathInfo, 0, -$n);
                 if ($pathInfo === '') {
                     // suffix alone is not allowed
                     return false;
                 }
             } else {
                 // suffix doesn't match
                 return false;
             }
         }
         return [$pathInfo, []];
     } else {
         Yii::trace('Pretty URL not enabled. Using default URL parsing logic.', __METHOD__);
         $route = $request->getQueryParam($this->routeParam, '');
         if (is_array($route)) {
             $route = '';
         }
         return [(string) $route, []];
     }
 }
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     if ($this->mode === self::CREATION_ONLY) {
         return false;
     }
     if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) {
         return false;
     }
     $pathInfo = $request->getPathInfo();
     $suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
     if ($suffix !== '' && $pathInfo !== '') {
         $n = strlen($suffix);
         if (substr_compare($pathInfo, $suffix, -$n) === 0) {
             $pathInfo = substr($pathInfo, 0, -$n);
             if ($pathInfo === '') {
                 // suffix alone is not allowed
                 return false;
             }
         } else {
             return false;
         }
     }
     if ($this->host !== null) {
         $pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo);
     }
     if (!preg_match($this->pattern, $pathInfo, $matches)) {
         return false;
     }
     foreach ($this->defaults as $name => $value) {
         if (!isset($matches[$name]) || $matches[$name] === '') {
             $matches[$name] = $value;
         }
     }
     $params = $this->defaults;
     $tr = [];
     foreach ($matches as $name => $value) {
         if (isset($this->_routeParams[$name])) {
             $tr[$this->_routeParams[$name]] = $value;
             unset($params[$name]);
         } elseif (isset($this->_paramRules[$name])) {
             $params[$name] = $value;
         }
     }
     if ($this->_routeRule !== null) {
         $route = strtr($this->route, $tr);
     } else {
         $route = $this->route;
     }
     Yii::trace("Request parsed with URL rule: {$this->name}", __METHOD__);
     return [$route, $params];
 }
 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     if ($this->mode === self::CREATION_ONLY) {
         return false;
     }
     if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) {
         return false;
     }
     $pathInfo = $request->getPathInfo();
     if ($this->host !== null) {
         $pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo);
     }
     $params = $request->getQueryParams();
     $suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
     $treeNode = null;
     if (!$pathInfo) {
         return false;
     }
     if (!preg_match('/\\/(?<id>\\d+)\\-(?<code>\\S+)$/i', "/" . $pathInfo, $matches)) {
         return false;
     }
     return ['cms/content-element/view', ['id' => $matches['id'], 'code' => $matches['code']]];
 }