Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a627d43

Browse files
committed
remove SignedUri
1 parent 576dd17 commit a627d43

File tree

2 files changed

+18
-71
lines changed

2 files changed

+18
-71
lines changed

src/Symfony/Component/HttpFoundation/SignedUri.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Symfony/Component/HttpFoundation/UriSigner.php

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
}
3838

3939
/**
40-
* Signs a URI and returns a SignedUri object.
40+
* Signs a URI.
4141
*
4242
* The given URI is signed by adding the query string parameter
4343
* which value depends on the URI and the secret.
@@ -50,8 +50,18 @@ public function __construct(
5050
*
5151
* The expiration is added as a query string parameter.
5252
*/
53-
public function signAndWrap(string $uri, \DateTimeInterface|\DateInterval|int|null $expiration = null): SignedUri
53+
public function sign(string $uri/* , \DateTimeInterface|\DateInterval|int|null $expiration = null */): string
5454
{
55+
$expiration = null;
56+
57+
if (1 < \func_num_args()) {
58+
$expiration = func_get_arg(1);
59+
}
60+
61+
if (null !== $expiration && !$expiration instanceof \DateTimeInterface && !$expiration instanceof \DateInterval && !\is_int($expiration)) {
62+
throw new \TypeError(\sprintf('The second argument of "%s()" must be an instance of "%s" or "%s", an integer or null (%s given).', __METHOD__, \DateTimeInterface::class, \DateInterval::class, get_debug_type($expiration)));
63+
}
64+
5565
$url = parse_url($uri);
5666
$params = [];
5767

@@ -68,42 +78,13 @@ public function signAndWrap(string $uri, \DateTimeInterface|\DateInterval|int|nu
6878
}
6979

7080
if (null !== $expiration) {
71-
$params[$this->expirationParameter] = $expiration = $this->getExpirationTime($expiration);
81+
$params[$this->expirationParameter] = $this->getExpirationTime($expiration);
7282
}
7383

7484
$uri = $this->buildUrl($url, $params);
7585
$params[$this->hashParameter] = $this->computeHash($uri);
7686

77-
return new SignedUri($this->buildUrl($url, $params), $expiration);
78-
}
79-
80-
/**
81-
* Signs a URI.
82-
*
83-
* The given URI is signed by adding the query string parameter
84-
* which value depends on the URI and the secret.
85-
*
86-
* @param \DateTimeInterface|\DateInterval|int|null $expiration The expiration for the given URI.
87-
* If $expiration is a \DateTimeInterface, it's expected to be the exact date + time.
88-
* If $expiration is a \DateInterval, the interval is added to "now" to get the date + time.
89-
* If $expiration is an int, it's expected to be a timestamp in seconds of the exact date + time.
90-
* If $expiration is null, no expiration.
91-
*
92-
* The expiration is added as a query string parameter.
93-
*/
94-
public function sign(string $uri/* , \DateTimeInterface|\DateInterval|int|null $expiration = null */): string
95-
{
96-
$expiration = null;
97-
98-
if (1 < \func_num_args()) {
99-
$expiration = func_get_arg(1);
100-
}
101-
102-
if (null !== $expiration && !$expiration instanceof \DateTimeInterface && !$expiration instanceof \DateInterval && !\is_int($expiration)) {
103-
throw new \TypeError(\sprintf('The second argument of "%s()" must be an instance of "%s" or "%s", an integer or null (%s given).', __METHOD__, \DateTimeInterface::class, \DateInterval::class, get_debug_type($expiration)));
104-
}
105-
106-
return (string) $this->signAndWrap($uri, $expiration);
87+
return $this->buildUrl($url, $params);
10788
}
10889

10990
/**
@@ -133,14 +114,14 @@ public function checkRequest(Request $request): bool
133114
}
134115

135116
/**
136-
* Verify a Request/string URI and return a SignedUri object.
117+
* Verify a Request or string URI.
137118
*
138119
* @throws UnSignedUriException If the URI is not signed
139120
* @throws UnverifiedSignedUriException If the signature is invalid
140121
* @throws ExpiredSignedUriException If the URI has expired
141122
* @throws SignedUriException
142123
*/
143-
public function verify(Request|string $uri): SignedUri
124+
public function verify(Request|string $uri): void
144125
{
145126
if ($uri instanceof Request) {
146127
$qs = ($qs = $uri->server->get('QUERY_STRING')) ? '?'.$qs : '';
@@ -167,11 +148,11 @@ public function verify(Request|string $uri): SignedUri
167148
}
168149

169150
if (!$expiration = $params[$this->expirationParameter] ?? false) {
170-
return new SignedUri($uri);
151+
return;
171152
}
172153

173154
if (time() < $expiration) {
174-
return new SignedUri($uri, $expiration);
155+
return;
175156
}
176157

177158
throw new ExpiredSignedUriException(

0 commit comments

Comments
 (0)