PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.4
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.4
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / league / glide / src / Signatures / Signature.php

Signature.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.4, at vendor/league/glide/src/Signatures/Signature.php

74 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace League\Glide\Signatures;
4
5 class Signature implements SignatureInterface
6 {
7 /**
8 * Secret key used to generate signature.
9 *
10 * @var string
11 */
12 protected $signKey;
13
14 /**
15 * Create Signature instance.
16 *
17 * @param string $signKey Secret key used to generate signature.
18 */
19 public function __construct($signKey)
20 {
21 $this->signKey = $signKey;
22 }
23
24 /**
25 * Add an HTTP signature to manipulation parameters.
26 *
27 * @param string $path The resource path.
28 * @param array $params The manipulation parameters.
29 *
30 * @return array The updated manipulation parameters.
31 */
32 public function addSignature($path, array $params)
33 {
34 return array_merge($params, ['s' => $this->generateSignature($path, $params)]);
35 }
36
37 /**
38 * Validate a request signature.
39 *
40 * @param string $path The resource path.
41 * @param array $params The manipulation params.
42 *
43 * @throws SignatureException
44 *
45 * @return void
46 */
47 public function validateRequest($path, array $params)
48 {
49 if (!isset($params['s'])) {
50 throw new SignatureException('Signature is missing.');
51 }
52
53 if ($params['s'] !== $this->generateSignature($path, $params)) {
54 throw new SignatureException('Signature is not valid.');
55 }
56 }
57
58 /**
59 * Generate an HTTP signature.
60 *
61 * @param string $path The resource path.
62 * @param array $params The manipulation parameters.
63 *
64 * @return string The generated HTTP signature.
65 */
66 public function generateSignature($path, array $params)
67 {
68 unset($params['s']);
69 ksort($params);
70
71 return md5($this->signKey.':'.ltrim($path, '/').'?'.http_build_query($params));
72 }
73 }
74