Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit f127729

Browse files
committed
Wither Method added for defaultReturnType
1 parent 3c4145d commit f127729

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/Dispatcher.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ private function createCachedRoute($routeCollector) : void
8282
}
8383
}
8484

85-
8685
private function cachedDispatcher() : FastRoute\Dispatcher\GroupCountBased
8786
{
8887
$dispatchData = include $this->cachedFile;

src/Router.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,20 @@ public function __construct(
118118
$this->defaultReturnType = ($defaultReturnType >=1 && $defaultReturnType <=7) ? $defaultReturnType : self::HTML;
119119
}
120120

121+
public function withDefaultReturnType(int $defaultReturnType) : self
122+
{
123+
$new = clone $this;
124+
$new->$defaultReturnType = $defaultReturnType;
125+
return $new;
126+
}
127+
121128
public function withSubFolder(string $folder) : self
122129
{
123130
$new = clone $this;
124131
$new->requestedPath = $this->extractFolder($this->requestedPath, $folder);
125132
return $new;
126133
}
134+
127135
public function withCacheFile(string $fileName) : self
128136
{
129137
$new = clone $this;
@@ -145,7 +153,6 @@ private function extractFolder(string $requestPath, string $folder) : string
145153
return $requestPath;
146154
}
147155

148-
149156
public function add(
150157
$requestMethods,
151158
string $route,

test/RouterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public function shouldThrowExceptionForInvalidCachedFile() : void
112112
$this->request->getUri()->getPath()
113113
);
114114
$router = $router->withSubFolder($this->config['folder'])
115-
->withCacheFile('/tmp/failed.cache');
115+
->withCacheFile('/tmp/failed.cache')
116+
->withDefaultReturnType(Router::HTML);
116117
$router->add(Router::GET, '/', 'app/main', Router::HTML, 'home');
117118
$router->getRoute();
118119
$this->assertFileExists(

0 commit comments

Comments
 (0)