/**
  * Parses the given request and returns the corresponding route and parameters.
  * @param 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)
 {
     $parts = SlugRuleBase::getParts($request, false);
     if (count($parts) === 0) {
         return false;
     }
     $this->_slugString = array_shift($parts);
     if (strlen($this->_slugString) < $this->minLength) {
         return false;
     }
     $slugClass = $this->slugClass;
     $slug = $slugClass::findBySlug($this->_slugString);
     if (!$slug) {
         return false;
         // this rule does not apply
     }
     $this->_slugModel = $slug;
     return parent::parseRequest($manager, $request);
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     if ($this->prefix === '' || strpos($pathInfo . '/', $this->prefix . '/') === 0) {
         return parent::parseRequest($manager, $request);
     } else {
         return false;
     }
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $suffix = (string) $this->suffix;
     if ($suffix !== '' && $pathInfo !== '') {
         $n = strlen($suffix);
         if (substr_compare($pathInfo, $suffix, -$n, $n) === 0) {
             $pathInfo = substr($pathInfo, 0, -$n);
             if ($pathInfo === '') {
                 // suffix alone is not allowed
                 return false;
             }
         } else {
             return false;
         }
     }
     if ($this->prefix === '' || strpos($pathInfo . '/', $this->prefix . '/') === 0) {
         return parent::parseRequest($manager, $request);
     } else {
         return false;
     }
 }