Passed
Push — main ( dd4eea...91afa7 )
by Dimitri
03:22
created

MiddlewareFinder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Cli\Commands\Routes;
13
14
use BlitzPHP\Container\Services;
15
use BlitzPHP\Router\Router;
16
17
/**
18
 * Trouve des middlewares.
19
 */
20
final class MiddlewareFinder
21
{
22
    private Router $router;
23
24
    public function __construct(?Router $router = null)
25
    {
26
        $this->router  = $router ?? Services::router();
27
    }
28
29
    /**
30
     * @param string $uri Chemin URI pour trouver des middlewares
31
     *
32
     * @return array Tableau d'alias de middleware ou de nom de classe
33
     */
34
    public function find(string $uri): array
35
    {
36
        $this->router->handle($uri);
37
38
        return $this->router->getMiddlewares();
39
    }
40
}
41