8000 remove `SignedUri` · symfony/symfony@ee8c09d · GitHub
[go: up one dir, main page]

Skip to content

Commit ee8c09d

Browse files
committed
remove SignedUri
1 parent 576dd17 commit ee8c09d

File tree

2 files changed

+18
-72
lines changed

2 files changed

+18
-72
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 & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\HttpFoundation;
1313

1414
use Symfony\Component\HttpFoundation\Exception\ExpiredSignedUriException;
15-
use Symfony\Component\HttpFoundation\Exception\LogicException;
1615
use Symfony\Component\HttpFoundation\Exception\SignedUriException;
1716
use Symfony\Component\HttpFoundation\Exception\UnSignedUriException;
1817
use Symfony\Component\HttpFoundation\Exception\UnverifiedSignedUriException;
@@ -37,7 +36,7 @@ public function __construct(
3736
}
3837

3938
/**
40-
* Signs a URI and returns a SignedUri object.
39+
* Signs a URI.
4140
*
4241
* The given URI is signed by adding the query string parameter
4342
* which value depends on the URI and the secret.
@@ -50,8 +49,18 @@ public function __construct(
5049
*
5150
* The expiration is added as a query string parameter.
5251
*/
53-
public function signAndWrap(string $uri, \DateTimeInterface|\DateInterval|int|null $expiration = null): SignedUri
52+
public function sign(string $uri/* , \DateTimeInterface|\DateInterval|int|null $expiration = null */): string
5453
{
54+
$expiration = null;
55+
56+
if (1 < \func_num_args()) {
57+
$expiration = func_get_arg(1);
58+
}
59+
60+
if (null !== $expiration && !$expiration instanceof \DateTimeInterface && !$expiration instanceof \DateInterval && !\is_int($expiration)) {
61+
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)));
62+
}
63+
5564
$url = parse_url($uri);
5665
$params = [];
5766

@@ -68,42 +77,13 @@ public function signAndWrap(string $uri, \DateTimeInterface|\DateInterval|int|nu
6877
}
6978

7079
if (null !== $expiration) {
71-
$params[$this->expirationParameter] = $expiration = $this->getExpirationTime($expiration);
80+
$params[$this->expirationParameter] = $this->getExpirationTime($expiration);
7281
}
7382

7483
$uri = $this->buildUrl($url, $params);
7584
$params[$this->hashParameter] = $this->computeHash($uri);
7685

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);
86+
return $this->buildUrl($url, $params);
10787
}
10888

10989
/**
@@ -133,14 +113,14 @@ public function checkRequest(Request $request): bool
133113
}
134114

135115
/**
136-
* Verify a Request/string URI and return a SignedUri object.
116+
* Verify a Request or string URI.
137117
*
138118
* @throws UnSignedUriException If the URI is not signed
139119
* @throws UnverifiedSignedUriException If the signature is invalid
140120
* @throws ExpiredSignedUriException If the URI has expired
141121
* @throws SignedUriException
142122
*/
143-
public function verify(Request|string $uri): SignedUri
123+
public function verify(Request|string $uri): void
144124
{
145125
if ($uri instanceof Request) {
146126
$qs = ($qs = $uri->server->get('QUERY_STRING')) ? '?'.$qs : '';
@@ -167,11 +147,11 @@ public function verify(Request|string $uri): SignedUri
167147
}
168148

169149
if (!$expiration = $params[$this->expirationParameter] ?? false) {
170-
return new SignedUri($uri);
150+
return;
171151
}
172152

173153
if (time() < $expiration) {
174-
return new SignedUri($uri, $expiration);
154+
return;
175155
}
176156

177157
throw new ExpiredSignedUriException(

0 commit comments

Comments
 (0)
0