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

Commit

Permalink
Wither Method added for defaultReturnType
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Dec 20, 2018
1 parent 3c4145d commit f127729
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ private function createCachedRoute($routeCollector) : void
}
}


private function cachedDispatcher() : FastRoute\Dispatcher\GroupCountBased
{
$dispatchData = include $this->cachedFile;
Expand Down
9 changes: 8 additions & 1 deletion src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -145,7 +153,6 @@ private function extractFolder(string $requestPath, string $folder) : string
return $requestPath;
}


public function add(
$requestMethods,
string $route,
Expand Down
3 changes: 2 additions & 1 deletion test/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f127729

Please sign in to comment.