From f1277297ad06f408f43869f699b25f8c943f6e38 Mon Sep 17 00:00:00 2001 From: Mehmet Korkmaz Date: Thu, 20 Dec 2018 03:07:54 +0300 Subject: [PATCH] Wither Method added for defaultReturnType --- src/Dispatcher.php | 1 - src/Router.php | 9 ++++++++- test/RouterTest.php | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Dispatcher.php b/src/Dispatcher.php index 72734c3..17de286 100644 --- a/src/Dispatcher.php +++ b/src/Dispatcher.php @@ -82,7 +82,6 @@ private function createCachedRoute($routeCollector) : void } } - private function cachedDispatcher() : FastRoute\Dispatcher\GroupCountBased { $dispatchData = include $this->cachedFile; diff --git a/src/Router.php b/src/Router.php index 4365c4f..c9608fd 100644 --- a/src/Router.php +++ b/src/Router.php @@ -118,12 +118,20 @@ public function __construct( $this->defaultReturnType = ($defaultReturnType >=1 && $defaultReturnType <=7) ? $defaultReturnType : self::HTML; } + public function withDefaultReturnType(int $defaultReturnType) : self + { + $new = clone $this; + $new->$defaultReturnType = $defaultReturnType; + return $new; + } + public function withSubFolder(string $folder) : self { $new = clone $this; $new->requestedPath = $this->extractFolder($this->requestedPath, $folder); return $new; } + public function withCacheFile(string $fileName) : self { $new = clone $this; @@ -145,7 +153,6 @@ private function extractFolder(string $requestPath, string $folder) : string return $requestPath; } - public function add( $requestMethods, string $route, diff --git a/test/RouterTest.php b/test/RouterTest.php index ca5636a..f56494a 100644 --- a/test/RouterTest.php +++ b/test/RouterTest.php @@ -112,7 +112,8 @@ public function shouldThrowExceptionForInvalidCachedFile() : void $this->request->getUri()->getPath() ); $router = $router->withSubFolder($this->config['folder']) - ->withCacheFile('/tmp/failed.cache'); + ->withCacheFile('/tmp/failed.cache') + ->withDefaultReturnType(Router::HTML); $router->add(Router::GET, '/', 'app/main', Router::HTML, 'home'); $router->getRoute(); $this->assertFileExists(