Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
/**
4
 * Slim Framework (https://slimframework.com)
5
 *
6
 * @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
7
 */
8
 
9
declare(strict_types=1);
10
 
11
namespace Slim\Routing;
12
 
13
use RuntimeException;
14
use Slim\Interfaces\DispatcherInterface;
15
use Slim\Interfaces\RouteCollectorInterface;
16
use Slim\Interfaces\RouteInterface;
17
use Slim\Interfaces\RouteResolverInterface;
18
 
19
use function rawurldecode;
20
 
21
/**
22
 * RouteResolver instantiates the FastRoute dispatcher
23
 * and computes the routing results of a given URI and request method
24
 */
25
class RouteResolver implements RouteResolverInterface
26
{
27
    protected RouteCollectorInterface $routeCollector;
28
 
29
    private DispatcherInterface $dispatcher;
30
 
31
    public function __construct(RouteCollectorInterface $routeCollector, ?DispatcherInterface $dispatcher = null)
32
    {
33
        $this->routeCollector = $routeCollector;
34
        $this->dispatcher = $dispatcher ?? new Dispatcher($routeCollector);
35
    }
36
 
37
    /**
38
     * @param string $uri Should be $request->getUri()->getPath()
39
     */
40
    public function computeRoutingResults(string $uri, string $method): RoutingResults
41
    {
42
        $uri = rawurldecode($uri);
43
        if ($uri === '' || $uri[0] !== '/') {
44
            $uri = '/' . $uri;
45
        }
46
        return $this->dispatcher->dispatch($method, $uri);
47
    }
48
 
49
    /**
50
     * @throws RuntimeException
51
     */
52
    public function resolveRoute(string $identifier): RouteInterface
53
    {
54
        return $this->routeCollector->lookupRoute($identifier);
55
    }
56
}