public function __construct($routes = null, $options = array())
{
/* setup custom route class */
if (isset($options['route_class'])) {
$this->matchedRouteClass = $options['route_class'];
}
if ($routes && !is_a($routes, 'Roller\\RouteSet')) {
throw new RouterException('Router constructor argument #1 is not a Roller\\RouteSet object.');
}
if (isset($options['enable_extension']) && extension_loaded('roller')) {
$this->extensionSupport = true;
}
/* if cache_id is defined (only), we use apc for caching defined routes */
if (isset($options['cache_id'])) {
$this->cacheId = $options['cache_id'];
if (extension_loaded('apc')) {
$this->cache = self::cache_type_apc;
if (false !== ($c = apc_fetch($options['cache_id']))) {
$this->routes = eval($c);
$this->hasCache = true;
}
}
}
if (isset($options['cache_dir'])) {
$this->cacheDir = $options['cache_dir'];
$this->cache = self::cache_type_file;
$cacheFile = $this->cacheDir . DIRECTORY_SEPARATOR . $this->cacheId;
$this->hasCache = false;
if (file_exists($cacheFile)) {
// check expiry
if ($this->cacheExpiry && filemtime($cacheFile) + $this->cacheExpiry < time()) {
// expired, do something ?
} else {
$this->routes = (require $cacheFile);
$this->hasCache = true;
}
}
}
if (isset($options['reload'])) {
$this->reload = $options['reload'];
}
if (null == $this->routes) {
$this->routes = $routes ?: new RouteSet();
}
}