diff --git a/src/Dispatcher.php b/src/Dispatcher.php index 17de286..fc97314 100644 --- a/src/Dispatcher.php +++ b/src/Dispatcher.php @@ -30,7 +30,7 @@ class Dispatcher /** * @var null|string */ - private $cachedFile; + private $cacheFile; /** * @var array @@ -43,11 +43,11 @@ class Dispatcher FastRoute\Dispatcher::NOT_FOUND => 404 ]; - public function __construct(array $routes, int $defaultReturnType, ?string $cachedFile) + public function __construct(array $routes, int $defaultReturnType, ?string $cacheFile) { $this->routes = $routes; $this->defaultReturnType = $defaultReturnType; - $this->cachedFile = $cachedFile; + $this->cacheFile = $cacheFile; } /* @@ -56,7 +56,7 @@ public function __construct(array $routes, int $defaultReturnType, ?string $cac public function dispatcher() : FastRoute\Dispatcher { $this->setRouteClosures(); - if ($this->cachedFile !== null && file_exists($this->cachedFile)) { + if ($this->cacheFile !== null && file_exists($this->cacheFile)) { return $this->cachedDispatcher(); } /** @@ -73,20 +73,20 @@ public function dispatcher() : FastRoute\Dispatcher private function createCachedRoute($routeCollector) : void { - if ($this->cachedFile !== null && !file_exists($this->cachedFile)) { + if ($this->cacheFile !== null && !file_exists($this->cacheFile)) { /** * @var FastRoute\RouteCollector $routeCollector */ $dispatchData = $routeCollector->getData(); - file_put_contents($this->cachedFile, 'cacheFile, 'cachedFile; + $dispatchData = require $this->cacheFile; if (!is_array($dispatchData)) { - throw new InvalidCacheFileException('Invalid cache file "' . $this->cachedFile . '"'); + throw new InvalidCacheFileException('Invalid cache file "' . $this->cacheFile . '"'); } return new FastRoute\Dispatcher\GroupCountBased($dispatchData); } diff --git a/src/Router.php b/src/Router.php index c9608fd..c347792 100644 --- a/src/Router.php +++ b/src/Router.php @@ -81,7 +81,7 @@ final class Router /** * @var null|string */ - private $cachedFile; + private $cacheFile; /** * Valid Request Methods array. @@ -135,7 +135,7 @@ public function withSubFolder(string $folder) : self public function withCacheFile(string $fileName) : self { $new = clone $this; - $new->cachedFile = $fileName; + $new->cacheFile = $fileName; return $new; } @@ -203,7 +203,7 @@ private function checkRequestMethodIsValid(string $requestMethod) : void public function getRoute() : Route { - $selamiDispatcher = new Dispatcher($this->routes, $this->defaultReturnType, $this->cachedFile); + $selamiDispatcher = new Dispatcher($this->routes, $this->defaultReturnType, $this->cacheFile); $routeInfo = $selamiDispatcher->dispatcher() ->dispatch($this->method, $this->requestedPath); return $selamiDispatcher->runDispatcher($routeInfo)