3 declare(strict_types = 1);
37 protected $originalParameters = [];
42 public function getRoutes(): array
49 $target = clone $this;
56 $target = clone $this;
57 $target->originalParameters = $originalParameters;
63 \uasort($this->
routes, [$this,
'compareForGeneration']);
87 $selfIsDefaultRoute = (bool)$self->getOption(
'_isDefault');
88 $otherIsDefaultRoute = (bool)$other->getOption(
'_isDefault');
90 if ($selfIsDefaultRoute && $otherIsDefaultRoute) {
94 if ($selfIsDefaultRoute && !$otherIsDefaultRoute) {
98 if (!$selfIsDefaultRoute && $otherIsDefaultRoute) {
106 $selfVariableNames = $self->compile()->getPathVariables();
107 $otherVariableNames = $other->compile()->getPathVariables();
108 if ($selfVariableNames === [] && $otherVariableNames === []) {
111 if ($selfVariableNames === [] && $otherVariableNames !== []) {
114 if ($selfVariableNames !== [] && $otherVariableNames === []) {
122 $selfVariables = $this->getAllRouteVariables($self);
123 $otherVariables = $this->getAllRouteVariables($other);
124 $missingSelfVariables = \array_diff_key(
126 $this->getRouteParameters($self)
128 $missingOtherVariables = \array_diff_key(
130 $this->getRouteParameters($other)
132 if ($missingSelfVariables === [] && $missingOtherVariables === []) {
133 $difference = \count($selfVariables) - \count($otherVariables);
134 return $difference * $action;
136 if ($missingSelfVariables === [] && $missingOtherVariables !== []) {
139 if ($missingSelfVariables !== [] && $missingOtherVariables === []) {
147 $missingSelfVariables = \array_diff_key(
148 $this->getMandatoryRouteVariables($self),
149 $this->getRouteParameters($self)
151 $missingOtherVariables = \array_diff_key(
152 $this->getMandatoryRouteVariables($other),
153 $this->getRouteParameters($other)
155 if ($missingSelfVariables === [] && $missingOtherVariables !== []) {
158 if ($missingSelfVariables !== [] && $missingOtherVariables === []) {
166 $missingSelfDefaults = \array_diff_key(
167 $this->getActualRouteDefaults($self),
168 $this->getRouteParameters($self)
170 $missingOtherDefaults = \array_diff_key(
171 $this->getActualRouteDefaults($other),
172 $this->getRouteParameters($other)
174 $difference = \count($missingSelfDefaults) - \count($missingOtherDefaults);
176 return $difference === 0 ? null : $difference * $action;
181 $selfDefaults = $this->getActualRouteDefaults($self);
182 $otherDefaults = $this->getActualRouteDefaults($other);
183 $difference = \count($selfDefaults) - \count($otherDefaults);
185 return $difference === 0 ? null : $difference * $action;
194 protected function getActualRouteDefaults(Route $route): array
196 return array_intersect_key(
197 $route->getDefaults(),
198 array_flip($route->compile()->getPathVariables())
206 protected function getAllRouteVariables(Route $route): array
208 return array_flip($route->compile()->getPathVariables());
215 protected function getMandatoryRouteVariables(Route $route): array
217 return \array_diff_key(
218 $this->getAllRouteVariables($route),
219 $route->getDefaults()
227 protected function getRouteParameters(Route $route): array
231 return $route->getOption(
'deflatedParameters') ?? $this->originalParameters;