Centralize routes file existence check in App\Router

This commit is contained in:
Hypolite Petovan 2020-10-15 21:45:51 -04:00
parent 7d705417a9
commit 06e3294415

View file

@ -93,6 +93,10 @@ class Router
$this->routeCollector = isset($routeCollector) ? $this->routeCollector = isset($routeCollector) ?
$routeCollector : $routeCollector :
new RouteCollector(new Std(), new GroupCountBased()); new RouteCollector(new Std(), new GroupCountBased());
if ($this->baseRoutesFilepath && !file_exists($this->baseRoutesFilepath)) {
throw new HTTPException\InternalServerErrorException('Routes file path does\'n exist.');
}
} }
/** /**
@ -249,7 +253,7 @@ class Router
{ {
$dispatchData = []; $dispatchData = [];
if ($this->baseRoutesFilepath && file_exists($this->baseRoutesFilepath)) { if ($this->baseRoutesFilepath) {
$dispatchData = require $this->baseRoutesFilepath; $dispatchData = require $this->baseRoutesFilepath;
if (!is_array($dispatchData)) { if (!is_array($dispatchData)) {
throw new HTTPException\InternalServerErrorException('Invalid base routes file'); throw new HTTPException\InternalServerErrorException('Invalid base routes file');
@ -280,7 +284,7 @@ class Router
$lastRoutesFileModifiedTime = $this->cache->get('lastRoutesFileModifiedTime'); $lastRoutesFileModifiedTime = $this->cache->get('lastRoutesFileModifiedTime');
$forceRecompute = false; $forceRecompute = false;
if ($this->baseRoutesFilepath && file_exists($this->baseRoutesFilepath)) { if ($this->baseRoutesFilepath) {
$routesFileModifiedTime = filemtime($this->baseRoutesFilepath); $routesFileModifiedTime = filemtime($this->baseRoutesFilepath);
$forceRecompute = $lastRoutesFileModifiedTime != $routesFileModifiedTime; $forceRecompute = $lastRoutesFileModifiedTime != $routesFileModifiedTime;
} }