123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- namespace yii\web;
- use Yii;
- use yii\base\BaseObject;
- abstract class CompositeUrlRule extends BaseObject implements UrlRuleInterface
- {
-
- protected $rules = [];
-
- protected $createStatus;
-
- abstract protected function createRules();
-
- public function init()
- {
- parent::init();
- $this->rules = $this->createRules();
- }
-
- public function parseRequest($manager, $request)
- {
- foreach ($this->rules as $rule) {
-
- $result = $rule->parseRequest($manager, $request);
- if (YII_DEBUG) {
- Yii::debug([
- 'rule' => method_exists($rule, '__toString') ? $rule->__toString() : get_class($rule),
- 'match' => $result !== false,
- 'parent' => self::className(),
- ], __METHOD__);
- }
- if ($result !== false) {
- return $result;
- }
- }
- return false;
- }
-
- public function createUrl($manager, $route, $params)
- {
- $this->createStatus = UrlRule::CREATE_STATUS_SUCCESS;
- $url = $this->iterateRules($this->rules, $manager, $route, $params);
- if ($url !== false) {
- return $url;
- }
- if ($this->createStatus === UrlRule::CREATE_STATUS_SUCCESS) {
-
- $this->createStatus = UrlRule::CREATE_STATUS_PARSING_ONLY;
- }
- return false;
- }
-
- protected function iterateRules($rules, $manager, $route, $params)
- {
-
- foreach ($rules as $rule) {
- $url = $rule->createUrl($manager, $route, $params);
- if ($url !== false) {
- $this->createStatus = UrlRule::CREATE_STATUS_SUCCESS;
- return $url;
- }
- if (
- $this->createStatus === null
- || !method_exists($rule, 'getCreateUrlStatus')
- || $rule->getCreateUrlStatus() === null
- ) {
- $this->createStatus = null;
- } else {
- $this->createStatus |= $rule->getCreateUrlStatus();
- }
- }
- return false;
- }
-
- public function getCreateUrlStatus()
- {
- return $this->createStatus;
- }
- }
|