Conditions | 8 |
Paths | 10 |
Total Lines | 25 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
40 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
41 | { |
||
42 | $uri = $request->getUri(); |
||
43 | $path = $uri->getPath(); |
||
44 | |||
45 | //Add/remove slash |
||
46 | if (strlen($path) > 1) { |
||
47 | if ($this->addSlash) { |
||
48 | if (substr($path, -1) !== '/' && !pathinfo($path, PATHINFO_EXTENSION)) { |
||
49 | $path .= '/'; |
||
50 | } |
||
51 | } else { |
||
52 | $path = rtrim($path, '/'); |
||
53 | } |
||
54 | } elseif ($path === '') { |
||
55 | $path = '/'; |
||
56 | } |
||
57 | |||
58 | //redirect |
||
59 | if ($this->redirectStatus !== false && ($uri->getPath() !== $path)) { |
||
60 | return $this->getRedirectResponse($request, $uri->withPath($path), $response); |
||
61 | } |
||
62 | |||
63 | return $next($request->withUri($uri->withPath($path)), $response); |
||
64 | } |
||
65 | } |
||
66 |