20
20
use Router \Http \Exceptions \InvalidRoute ;
21
21
22
22
class Router {
23
- private array $ beforeMiddleware = [];
24
- private array $ afterMiddleware = [];
25
- private array $ routes = [
23
+ protected array $ beforeMiddleware = [];
24
+ protected array $ afterMiddleware = [];
25
+ protected array $ routes = [
26
26
Methods::GET ->value => [],
27
27
Methods::POST ->value => [],
28
28
Methods::PATCH ->value => [],
@@ -31,17 +31,17 @@ class Router {
31
31
Methods::OPTIONS ->value => [],
32
32
Methods::PUT ->value => []
33
33
];
34
- private array $ E404Handlers = [];
35
- private array $ E500Handlers = [];
36
- private string $ baseRoute = "" ;
37
- private Environment $ twig ;
38
- private HttpServer $ http ;
34
+ protected array $ E404Handlers = [];
35
+ protected array $ E500Handlers = [];
36
+ protected string $ baseRoute = "" ;
37
+ protected Environment $ twig ;
38
+ protected HttpServer $ http ;
39
39
40
40
/**
41
41
* @param SocketServer $socket
42
42
* @param bool $dev
43
43
*/
44
- public function __construct (private SocketServer $ socket , private bool $ dev = false ) {
44
+ public function __construct (protected SocketServer $ socket , protected bool $ dev = false ) {
45
45
if ($ this ->dev ) {
46
46
$ this ->twig = new Environment (new \Twig \Loader \FilesystemLoader (__DIR__ . "/Exceptions/views " ));
47
47
}
@@ -307,7 +307,7 @@ public function getSocketServer(): ?SocketServer
307
307
* @throws InvalidResponse
308
308
* @return ResponseInterface
309
309
*/
310
- private function invoke (ServerRequestInterface $ request , ?ResponseInterface $ response , ?Closure $ next , array $ route , mixed ...$ extra ): ResponseInterface
310
+ protected function invoke (ServerRequestInterface $ request , ?ResponseInterface $ response , ?Closure $ next , array $ route , mixed ...$ extra ): ResponseInterface
311
311
{
312
312
if (is_null ($ response ) && !is_null ($ next )) {
313
313
$ params = [$ request , $ next ];
@@ -343,7 +343,7 @@ private function invoke(ServerRequestInterface $request, ?ResponseInterface $res
343
343
* @throws InvalidRoute
344
344
* @return ResponseInterface
345
345
*/
346
- private function handle (ServerRequestInterface $ request ): ResponseInterface
346
+ protected function handle (ServerRequestInterface $ request ): ResponseInterface
347
347
{
348
348
$ beforeMiddleware = $ this ->getMatchingRoutes ($ request , $ this ->beforeMiddleware , true )[0 ] ?? null ;
349
349
$ targetRoute = $ this ->getMatchingRoutes ($ request , $ this ->routes [$ request ->getMethod ()], true )[0 ] ?? null ;
@@ -380,7 +380,7 @@ private function handle(ServerRequestInterface $request): ResponseInterface
380
380
* @param array|null $matches
381
381
* @return bool
382
382
*/
383
- private function patternMatches (string $ pattern , string $ uri , array |null &$ matches ): bool
383
+ protected function patternMatches (string $ pattern , string $ uri , array |null &$ matches ): bool
384
384
{
385
385
$ pattern = preg_replace ('/\/{(.*?)}/ ' , '/(.*?) ' , $ pattern );
386
386
@@ -392,7 +392,7 @@ private function patternMatches(string $pattern, string $uri, array|null &$match
392
392
* @param array $routes
393
393
* @return array
394
394
*/
395
- private function getMatchingRoutes (ServerRequest $ request , array $ routes , bool $ findOne = false ): array
395
+ protected function getMatchingRoutes (ServerRequest $ request , array $ routes , bool $ findOne = false ): array
396
396
{
397
397
$ uri = explode ("? " , $ request ->getRequestTarget ())[0 ];
398
398
0 commit comments