/** * @see IRoute */ public function encode(array $params) { $pieces = array(); foreach ($this->parsedRule['components'] as $component) { $name = $component['name']; if ($component['isVar']) { if (!isset($params[$name])) { throw new MissingParamException(sprintf("Missing parameter '%s' in route '%s'", $name, $this->routeName)); } if ($component['choices'] && !in_array($params[$name], $component['choices'])) { throw new InvalidParamException(sprintf("Invalid value '%s' for parameter '%s' in route '%s'", $params[$name], $name, $this->routeName)); } $pieces[] = urlencode($params[$name]); } else { $pieces[] = urlencode($name); } unset($params[$name]); } $path = "/" . implode("/", $pieces); if ($this->parsedRule['varargs']) { $path .= VarargsHelper::serialize($params); } else { if (!empty($params)) { throw new InvalidParamException(sprintf('The route %s cannot accept additional parameters, but found other %s', $this->routeName, count($params))); } } return $path; }
/** * @expectedException MistyRouting\Exception\InvalidParamException */ public function testSerialize_invalidParam() { VarargsHelper::serialize(array('' => 'value')); }