|
|
@@ -377,6 +377,28 @@ class Route
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Apply persistent parameters to a URL array. Persistent parameters are a
|
|
|
+ * special key used during route creation to force route parameters to
|
|
|
+ * persist when omitted from a URL array.
|
|
|
+ *
|
|
|
+ * @param array $url The array to apply persistent parameters to.
|
|
|
+ * @param array $params An array of persistent values to replace persistent ones.
|
|
|
+ * @return array An array with persistent parameters applied.
|
|
|
+ */
|
|
|
+ public function persistParams(array $url, array $params)
|
|
|
+ {
|
|
|
+ if (empty($this->options['persist']) || !is_array($this->options['persist'])) {
|
|
|
+ return $url;
|
|
|
+ }
|
|
|
+ foreach ($this->options['persist'] as $persistKey) {
|
|
|
+ if (array_key_exists($persistKey, $params) && !isset($url[$persistKey])) {
|
|
|
+ $url[$persistKey] = $params[$persistKey];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $url;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Check if a URL array matches this route instance.
|
|
|
*
|
|
|
* If the URL matches the route parameters and settings, then
|
|
|
@@ -385,8 +407,8 @@ class Route
|
|
|
*
|
|
|
* @param array $url An array of parameters to check matching with.
|
|
|
* @param array $context An array of the current request context.
|
|
|
- * Contains information such as the current host, scheme, port, and base
|
|
|
- * directory.
|
|
|
+ * Contains information such as the current host, scheme, port, base
|
|
|
+ * directory and other url params.
|
|
|
* @return mixed Either a string url for the parameters if they match or false.
|
|
|
*/
|
|
|
public function match(array $url, array $context = [])
|
|
|
@@ -395,7 +417,10 @@ class Route
|
|
|
$this->compile();
|
|
|
}
|
|
|
$defaults = $this->defaults;
|
|
|
+ $context += ['params' => []];
|
|
|
|
|
|
+ $url = $this->persistParams($url, $context['params']);
|
|
|
+ unset($context['params']);
|
|
|
$hostOptions = array_intersect_key($url, $context);
|
|
|
|
|
|
// Check for properties that will cause an
|