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 Slim\Interfaces\DispatcherInterface;
14
 
15
use function rawurldecode;
16
 
17
class RoutingResults
18
{
19
    public const NOT_FOUND = 0;
20
    public const FOUND = 1;
21
    public const METHOD_NOT_ALLOWED = 2;
22
 
23
    protected DispatcherInterface $dispatcher;
24
 
25
    protected string $method;
26
 
27
    protected string $uri;
28
 
29
    /**
30
     * The status is one of the constants shown above
31
     * NOT_FOUND = 0
32
     * FOUND = 1
33
     * METHOD_NOT_ALLOWED = 2
34
     */
35
    protected int $routeStatus;
36
 
37
    protected ?string $routeIdentifier = null;
38
 
39
    /**
40
     * @var array<string, string>
41
     */
42
    protected array $routeArguments;
43
 
44
    /**
45
     * @param array<string, string> $routeArguments
46
     */
47
    public function __construct(
48
        DispatcherInterface $dispatcher,
49
        string $method,
50
        string $uri,
51
        int $routeStatus,
52
        ?string $routeIdentifier = null,
53
        array $routeArguments = []
54
    ) {
55
        $this->dispatcher = $dispatcher;
56
        $this->method = $method;
57
        $this->uri = $uri;
58
        $this->routeStatus = $routeStatus;
59
        $this->routeIdentifier = $routeIdentifier;
60
        $this->routeArguments = $routeArguments;
61
    }
62
 
63
    public function getDispatcher(): DispatcherInterface
64
    {
65
        return $this->dispatcher;
66
    }
67
 
68
    public function getMethod(): string
69
    {
70
        return $this->method;
71
    }
72
 
73
    public function getUri(): string
74
    {
75
        return $this->uri;
76
    }
77
 
78
    public function getRouteStatus(): int
79
    {
80
        return $this->routeStatus;
81
    }
82
 
83
    public function getRouteIdentifier(): ?string
84
    {
85
        return $this->routeIdentifier;
86
    }
87
 
88
    /**
89
     * @return array<string, string>
90
     */
91
    public function getRouteArguments(bool $urlDecode = true): array
92
    {
93
        if (!$urlDecode) {
94
            return $this->routeArguments;
95
        }
96
 
97
        $routeArguments = [];
98
        foreach ($this->routeArguments as $key => $value) {
99
            $routeArguments[$key] = rawurldecode($value);
100
        }
101
 
102
        return $routeArguments;
103
    }
104
 
105
    /**
106
     * @return string[]
107
     */
108
    public function getAllowedMethods(): array
109
    {
110
        return $this->dispatcher->getAllowedMethods($this->uri);
111
    }
112
}