public function makeUrl(IRoutingRule $rule, array $parameters = array())
 {
     $vars = array_merge($rule->getParameters(), $parameters);
     $url = $this->replaceVariablesWithParameters($rule->getPattern(), $vars);
     if ($this->hasVariableHolders($url)) {
         throw new InvalidArgumentException("Not all variables where substituted, this url remained: {$url}");
     }
     return $url;
 }
 /**
  * Creates regular expression, which represents requirements and pattern
  * provided by IRoutingRule
  *
  * @param IRoutingRule $rule
  * @return CompiledRule
  */
 public function compile(IRoutingRule $rule)
 {
     $regex = $this->escapePattern($rule->getPattern());
     list($variableStrings, $variableNames) = $this->findVariablesInPattern($regex);
     $unassigned = array();
     foreach ($variableNames as $name) {
         $unassigned[$name] = null;
     }
     $rawRequirements = array_merge($unassigned, $rule->getRequirements());
     $assigned = $this->prepareSubPatterns($rawRequirements);
     for ($i = 0; $i < count($variableStrings); $i++) {
         $regex = str_replace($variableStrings[$i], $assigned[$variableNames[$i]], $regex);
     }
     $regex = '/^' . $regex . '$/';
     return $this->factory->createCompiledRule($rule, $regex);
 }