public function init()
{
parent::init();
if ($this->normalizer !== false) {
$this->normalizer = Yii::createObject($this->normalizer);
if (!$this->normalizer instanceof UrlNormalizer) {
throw new InvalidConfigException('`' . get_class($this) . '::normalizer` should be an instance of `' . UrlNormalizer::className() . '` or its DI compatible configuration.');
}
}
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 = $this->cacheKey;
$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);
}
}