Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (empty($this->host)) {
         throw new InvalidConfigException('`host` property must be set.');
     }
     parent::init();
 }
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (empty($this->controller)) {
         throw new InvalidConfigException('"controller" must be set.');
     }
     $controllers = [];
     foreach ((array) $this->controller as $urlName => $controller) {
         if (is_integer($urlName)) {
             $urlName = $this->pluralize ? Inflector::pluralize($controller) : $controller;
         }
         $controllers[$urlName] = $controller;
     }
     $this->controller = $controllers;
     $this->prefix = trim($this->prefix, '/');
     parent::init();
 }
Ejemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function createUrl($manager, $route, $params)
 {
     if ($this->routePrefix === '' || strpos($route, $this->routePrefix . '/') === 0) {
         return parent::createUrl($manager, $route, $params);
     } else {
         return false;
     }
 }