Skip to content

Commit 3f76df3

Browse files
Skullbockivanvermeyen
authored andcommitted
Add support for signed Routes with locale (#5)
1 parent 42992a0 commit 3f76df3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/UrlGenerator.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ public function route($name, $parameters = [], $absolute = true, $locale = null)
6868

6969
return $url;
7070
}
71+
72+
/**
73+
* Create a signed route URL for a named route.
74+
*
75+
* @param string $name
76+
* @param array $parameters
77+
* @param \DateTimeInterface|\DateInterval|int $expiration
78+
* @param bool $absolute
79+
* @return string
80+
*/
81+
public function signedRoute($name, $parameters = [], $expiration = null, $absolute = true, $locale = null)
82+
{
83+
$parameters = $this->formatParameters($parameters);
84+
85+
if ($expiration) {
86+
$parameters = $parameters + ['expires' => $this->availableAt($expiration)];
87+
}
88+
89+
ksort($parameters);
90+
91+
$key = call_user_func($this->keyResolver);
92+
93+
return $this->route($name, $parameters + [
94+
'signature' => hash_hmac('sha256', $this->route($name, $parameters, $absolute, $locale), $key),
95+
], $absolute, $locale);
96+
}
7197

7298
/**
7399
* Strip the locale from the beginning of a route name.

0 commit comments

Comments
 (0)