Skip to content

Instantly share code, notes, and snippets.

@acorncom
Forked from creocoder/gist:9334d4fb7d3c8e84c984
Last active August 29, 2015 14:13
Show Gist options
  • Save acorncom/21320eb51f5d816da242 to your computer and use it in GitHub Desktop.
Save acorncom/21320eb51f5d816da242 to your computer and use it in GitHub Desktop.
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