Build pattern based on the route to match uri.

@param  Parameter[] $parameters
@return void
193854
protected function build(array $parameters)
    {
        $route    = preg_split('`([/.-])`', $this->route, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $regex    = array();
        $position = 0;

        foreach ($route as $index => $element) {
            switch ($element) {
                case '.':
                    $regex[$element . '-' . $index] = '\\' . $element;
                    break;
                case '/':
                case '-':
                    $regex[$element . '-' . $index] = $element;
                    break;

                default:

                    if (':' === substr($element, 0, 1)) {
                        $elementName = substr($element, 1);
                        $position++;

                        if (!isset($parameters[$elementName])) {
                            $parameters[$elementName] = new Parameter($elementName);
                        }

                        $regex[$elementName] = '(' . $parameters[$elementName]->getType() . ')';

                        $this->parameterCollection->add($parameters[$elementName]);
                    } else {
                        $regex[$element] = $element;
                    }
            }
        }

        $this->pattern = '`^' . implode('', $regex) . '$`i';
    }
271514
protected function getPathsForBundleResource($parameters)
    {
        $parameters['%site_dir%']     = $this->kernel->getBundle('SiteBundle')->getPath().'/Resources';
        $parameters['%cms_dir%']      = $this->kernel->getBundle('CMSBundle')->getPath().'/Resources';
        $parameters['%module_theme%'] = $this->moduleTheme;

        return parent::getPathsForBundleResource($parameters);
    }
187133
public function setParameters($parameters)
    {
        parent::setParameters($parameters);
        if ($parameters !== null) {
            for ($i = 0, $size = count($parameters); $i < $size; $i++) {
                $paramname = $parameters[$i]->getName();
                switch (strtolower($paramname)) {
                    case self::EXPRESSION_KEY:
                        $this->setExpression($parameters[$i]->getValue());
                        break;
                    case self::CASE_KEY:
                        $this->setCasesensitive(Project::toBoolean($parameters[$i]->getValue()));
                        break;
                    case self::ML_KEY:
                        $this->setMultiLine(Project::toBoolean($parameters[$i]->getValue()));
                        break;
                    default:
                        $this->setError("Invalid parameter " . $paramname);
                }
            } // for each param
        } // if params
    }
897397
public function addRoutes($routes)
	{
		foreach ($routes as $route) {
			foreach (explode('|', $route[0]) as $method) {
				$this->routes[$method][] = array(
					'pattern' => $route[1],
					'callable' => $route[2]
				);
			}
		}
	}
861460
private function buildQuery(array $parameters)
        {
            // no parameters?
            if(empty($parameters)) {
                return '';
            }

            // encode the keys
            $keys = self::urlencode_rfc3986(array_keys($parameters));

            // encode the values
            $values = self::urlencode_rfc3986(array_values($parameters));

            // reset the parameters
            $parameters = array_combine($keys, $values);

            // sort parameters by key
            uksort($parameters, 'strcmp');

            // loop parameters
            foreach ($parameters as $key => $value) {
                // sort by value
                if(Arrays::is($value)) $parameters[$key] = natsort($value);
            }

            // process parameters
            foreach ($parameters as $key => $value) {
                $chunks[] = $key . '=' . str_replace('%25', '%', $value);
            }

            // return
            return implode('&', $chunks);
        }
245200
public function getPath(array $parameters)
    {
        foreach ($parameters as $parameterName => $parameterValue) {
            $parameterMethod = 'set' . ucfirst($parameterName);

            $this->$parameterMethod($parameterValue);
        }

        return $this->buildPath();
    }
888386
public function view($parameters)
    {
        if (!headers_sent()) {
            header('Content-Type: application/json;charset=utf-8');
        }

        //If JSONP requested (if callback is requested though GET)
        if (($callback = \Phramework\Phramework::getCallback())) {
            echo $callback;
            echo '([';
            echo json_encode($parameters);
            echo '])';
        } else {
            echo json_encode($parameters);
        }
    }
1340309
protected function prepareParameters(array $parameters)
	{
		return array_merge($this->_parameters, self::resolveAliases($parameters, $this->aliases));
	}
497025
public function getUri($parameters = [])
    {
        $uri = $this->uri;
        foreach ($parameters as $name => $value) {
            if (!is_numeric($name)) {
                $uri = str_replace(['#'.$name, '::'.$name, ':'.$name], $value, $uri);
                unset($parameters[$name]);
            }
        }
        ksort($parameters);
        foreach ($parameters as $value) {
            $uri = preg_replace('@^([^:#]*)(:|::|#)\w+@', '${1}'.$value, $uri);
        }
        $uri = preg_replace('@\(([^):#]*)\)@', '${1}', $uri);
        $uri = preg_replace('@\([^)]*\)@', '', $uri);
        $uri = preg_replace('@(:|::|#)(\w+)@', '', $uri);
        return $uri;
    }
585799
public function match($url, $to = null, array $params = array())
    {
        if (!$params && is_array($to)) {
            $params = $to;
            $to = null;
        }
        $this->createAndAddRoute($url, $to, $params);
    }
19247
public function buildRoutePattern()
	{
		$path = $this->prefix ? rtrim($this->prefix . '/' . $this->route, '/') : $this->route;

		return '~^' . preg_replace_callback(self::VAR_PATTERN, function($matches) {
			$this->parameter[] = $key = $matches[1];

			// Shorthand validation only if not set using the validation-method
			if (isset($matches[2]) && !isset($this->parameterPattern[$key])) {
				$this->parameterPattern[$key] = $matches[2];
			}
			return $this->buildParameterPattern($key);
		}, $path) . ($this->terminated ? '$' : '') . '~i';

	}
492361
private function buildUri($uri, $params)
    {
        $parse_url = parse_url($uri);

        // Add our params to the parsed uri
        foreach ( $params as $k => $v ) {
            if (isset($parse_url[$k])) {
                $parse_url[$k] .= "&" . http_build_query($v);
            } else {
                $parse_url[$k] = http_build_query($v);
            }
        }

        // Put humpty dumpty back together
        return
            ((isset($parse_url["scheme"])) ? $parse_url["scheme"] . "://" : "")
            . ((isset($parse_url["user"])) ? $parse_url["user"]
            . ((isset($parse_url["pass"])) ? ":" . $parse_url["pass"] : "") . "@" : "")
            . ((isset($parse_url["host"])) ? $parse_url["host"] : "")
            . ((isset($parse_url["port"])) ? ":" . $parse_url["port"] : "")
            . ((isset($parse_url["path"])) ? $parse_url["path"] : "")
            . ((isset($parse_url["query"])) ? "?" . $parse_url["query"] : "")
            . ((isset($parse_url["fragment"])) ? "#" . $parse_url["fragment"] : "")
        ;
    }
371219
public function build($parameters = array())
    {
        // sort array by key to generate the container name
        ksort($parameters);

        // needed for new packages installed
        $composerClass = array_filter(get_declared_classes(), function ($item) {
            if (0 === strpos($item, 'ComposerAutoloaderInit')) return true;
        });
        $composerClass = array_pop($composerClass);

        // generate hash
        $parametersHash = md5(serialize($parameters) . $composerClass);

        $containerClass = 'Container' . $parametersHash;

        $isDebug = true;

        $file = sprintf('%s/ladybug_cache/%s.php', sys_get_temp_dir(), $parametersHash);
        $containerConfigCache = new ConfigCache($file, $isDebug);

        if (!$containerConfigCache->isFresh()) {
            $this->initializeContainer();
            $this->loadServices();
            $this->loadThemes();
            $this->loadPlugins();
            $this->setParameters($parameters);

            $this->container->compile();

            $dumper = new PhpDumper($this->container);
            $containerConfigCache->write(
                $dumper->dump(array('class' => $containerClass)),
                $this->container->getResources()
            );
        } else {
            require_once $file;

            $this->container = new $containerClass();
        }

    }
707280
public function setParameters($parameters)
    {
        $this->parameters = [];
        
        foreach ($parameters as $parameter) {
            $this->append($parameter);
        }
        
        return $this;
    }
889924
public function setParameters(array $parameters)
    {
        $this->clearCachedValueIf($this->params != $parameters);
        $this->params = $parameters;
    }
888489
public function setParameters($parameters)
    {
        parent::setParameters($parameters);
        if ($parameters !== null) {
            for ($i = 0, $len = count($parameters); $i < $len; $i++) {
                $paramname = $parameters[$i]->getName();
                switch (strtolower($paramname)) {
                    case self::NAME_KEY:
                        $this->setName($parameters[$i]->getValue());
                        break;
                    case self::CASE_KEY:
                        $this->setCasesensitive(Project::toBoolean($parameters[$i]->getValue()));
                        break;
                    case self::NEGATE_KEY:
                        $this->setNegate(Project::toBoolean($parameters[$i]->getValue()));
                        break;
                    case self::REGEX_KEY:
                        $this->setRegex($parameters[$i]->getValue());
                        break;
                    default:
                        $this->setError("Invalid parameter " . $paramname);
                }
            } // for each param
        } // if params
    }
1323436
public static function replace($uri, $parameters = [])
    {
        $parameters = (array) $parameters;

        $uri = static::replaceRouteParameters($uri, $parameters);
        $uri = str_replace('//', '/', $uri);

        return $uri;
    }