/** * {@inheritdoc} */ public function generateFromTokens(RouteInterface $route, array $tokens, array $parameters = [], $tokenSeparator) { $graph = []; if (empty($tokens)) { return $route->getPattern(); } /** @var Token $token */ foreach ($tokens as $token) { if ($token->isParameter()) { if (!isset($parameters[$token->getExpression()])) { throw new InvalidArgumentException(sprintf('Missing parameter %s', $token->getExpression())); } $value = $parameters[$token->getExpression()]; $requirements = $token->getRequirements(); if (isset($requirements['wildcard']) && true == $requirements['wildcard']) { if ($value === '*' || $value === 'all') { $graph[] = $value; continue; //next token } } if (isset($requirements['pattern'])) { $pattern = $requirements['pattern']; if (1 === preg_match("#^{$pattern}#i", $value)) { $graph[] = $value; continue; //next token } else { throw new InvalidArgumentException(sprintf('Invalid parameters %s, must match %s', $token->getExpression(), $pattern)); } } else { $graph[] = $value; } } else { $graph[] = $token->getExpression(); } } return implode($tokenSeparator, $graph); }
public function testGetRequirements() { $this->assertEquals($this->requirements, $this->route->getRequirements()); }