-
-
Save acorncom/21320eb51f5d816da242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace common\components; | |
use \yii\web\UrlManager as BaseUrlManager; | |
class UrlManager extends BaseUrlManager { | |
protected $choice; | |
public function init() { | |
Component::init(); | |
if ($this->choice === null) { | |
$this->choice = $this->rulesChooser(); | |
} | |
// ugly, we'll clean this up in a bit | |
$this->rules = $this->rules[$this->choice]; | |
if (!$this->enablePrettyUrl || empty($this->rules)) { | |
return; | |
} | |
if (is_string($this->cache)) { | |
$this->cache = Yii::$app->get($this->cache, false); | |
} | |
if ($this->cache instanceof Cache) { | |
$cacheKey = __CLASS__ . $this->choice; | |
$hash = md5(json_encode($this->rules)); | |
if (($data = $this->cache->get($cacheKey)) !== false && isset($data[1]) && $data[1] === $hash) { | |
$this->rules = $data[0]; | |
} else { | |
$this->rules = $this->buildRules($this->rules); | |
$this->cache->set($cacheKey, [$this->rules, $hash]); | |
} | |
} else { | |
$this->rules = $this->buildRules($this->rules); | |
} | |
} | |
protected function rulesChooser() { | |
... | |
} | |
public function parseRequest($request) { | |
// .. not sure it's needed | |
} | |
public function createUrl($params) { | |
// we will need this | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment