Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/http-kernel/UriSigner.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
17 * @author Fabien Potencier <fabien@symfony.com> | 17 * @author Fabien Potencier <fabien@symfony.com> |
18 */ | 18 */ |
19 class UriSigner | 19 class UriSigner |
20 { | 20 { |
21 private $secret; | 21 private $secret; |
22 private $parameter; | |
22 | 23 |
23 /** | 24 /** |
24 * Constructor. | 25 * @param string $secret A secret |
25 * | 26 * @param string $parameter Query string parameter to use |
26 * @param string $secret A secret | |
27 */ | 27 */ |
28 public function __construct($secret) | 28 public function __construct($secret, $parameter = '_hash') |
29 { | 29 { |
30 $this->secret = $secret; | 30 $this->secret = $secret; |
31 $this->parameter = $parameter; | |
31 } | 32 } |
32 | 33 |
33 /** | 34 /** |
34 * Signs a URI. | 35 * Signs a URI. |
35 * | 36 * |
36 * The given URI is signed by adding a _hash query string parameter | 37 * The given URI is signed by adding the query string parameter |
37 * which value depends on the URI and the secret. | 38 * which value depends on the URI and the secret. |
38 * | 39 * |
39 * @param string $uri A URI to sign | 40 * @param string $uri A URI to sign |
40 * | 41 * |
41 * @return string The signed URI | 42 * @return string The signed URI |
49 $params = array(); | 50 $params = array(); |
50 } | 51 } |
51 | 52 |
52 $uri = $this->buildUrl($url, $params); | 53 $uri = $this->buildUrl($url, $params); |
53 | 54 |
54 return $uri.(false === strpos($uri, '?') ? '?' : '&').'_hash='.$this->computeHash($uri); | 55 return $uri.(false === strpos($uri, '?') ? '?' : '&').$this->parameter.'='.$this->computeHash($uri); |
55 } | 56 } |
56 | 57 |
57 /** | 58 /** |
58 * Checks that a URI contains the correct hash. | 59 * Checks that a URI contains the correct hash. |
59 * | |
60 * The _hash query string parameter must be the last one | |
61 * (as it is generated that way by the sign() method, it should | |
62 * never be a problem). | |
63 * | 60 * |
64 * @param string $uri A signed URI | 61 * @param string $uri A signed URI |
65 * | 62 * |
66 * @return bool True if the URI is signed correctly, false otherwise | 63 * @return bool True if the URI is signed correctly, false otherwise |
67 */ | 64 */ |
72 parse_str($url['query'], $params); | 69 parse_str($url['query'], $params); |
73 } else { | 70 } else { |
74 $params = array(); | 71 $params = array(); |
75 } | 72 } |
76 | 73 |
77 if (empty($params['_hash'])) { | 74 if (empty($params[$this->parameter])) { |
78 return false; | 75 return false; |
79 } | 76 } |
80 | 77 |
81 $hash = urlencode($params['_hash']); | 78 $hash = urlencode($params[$this->parameter]); |
82 unset($params['_hash']); | 79 unset($params[$this->parameter]); |
83 | 80 |
84 return $this->computeHash($this->buildUrl($url, $params)) === $hash; | 81 return $this->computeHash($this->buildUrl($url, $params)) === $hash; |
85 } | 82 } |
86 | 83 |
87 private function computeHash($uri) | 84 private function computeHash($uri) |