-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRouteInfo.php
84 lines (70 loc) · 1.63 KB
/
RouteInfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
namespace Shopsys\HttpSmokeTesting;
use Symfony\Component\Routing\Route;
class RouteInfo
{
private string $routeName;
/**
* @param string $routeName
* @param \Symfony\Component\Routing\Route $route
* @param array $annotations
*/
public function __construct($routeName, private readonly Route $route, private readonly array $annotations = [])
{
$this->routeName = $routeName;
}
/**
* @return string
*/
public function getRouteName()
{
return $this->routeName;
}
/**
* @return string
*/
public function getRoutePath()
{
return $this->route->getPath();
}
/**
* @return string
*/
public function getRouteCondition()
{
return $this->route->getCondition();
}
/**
* @param string $method
* @return bool
*/
public function isHttpMethodAllowed($method)
{
$methods = $this->route->getMethods();
return count($methods) === 0 || in_array(strtoupper($method), $methods, true);
}
/**
* @param string $name
* @return bool
*/
public function isRouteParameterRequired($name)
{
return !$this->route->hasDefault($name) && in_array($name, $this->getRouteParameterNames(), true);
}
/**
* @return string[]
*/
public function getRouteParameterNames()
{
$compiledRoute = $this->route->compile();
return $compiledRoute->getVariables();
}
/**
* @return array
*/
public function getAnnotations(): array
{
return $this->annotations;
}
}