1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace Aws\CloudFront;
- class CookieSigner
- {
-
- private $signer;
- private static $schemes = [
- 'http' => true,
- 'https' => true,
- ];
-
- public function __construct($keyPairId, $privateKey)
- {
- $this->signer = new Signer($keyPairId, $privateKey);
- }
-
- public function getSignedCookie($url = null, $expires = null, $policy = null)
- {
- if ($url) {
- $this->validateUrl($url);
- }
- $cookieParameters = [];
- $signature = $this->signer->getSignature($url, $expires, $policy);
- foreach ($signature as $key => $value) {
- $cookieParameters["CloudFront-$key"] = $value;
- }
- return $cookieParameters;
- }
- private function validateUrl($url)
- {
- $scheme = str_replace('*', '', explode('://', $url)[0]);
- if (empty(self::$schemes[strtolower($scheme)])) {
- throw new \InvalidArgumentException('Invalid or missing URI scheme');
- }
- }
- }
|