Skip to content

Commit 42c9655

Browse files
committed
Fixed config publishing;
$expiration default behaviour moved to internal `sign()` method instead of helper
1 parent 646e296 commit 42c9655

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to `laravel-cloudfront-url-signer` will be documented in this file.
44

5+
## 0.1.2 - 2018-02-09
6+
7+
- Fixed config publishing
8+
- $expiration default behaviour moved to internal `sign()` method instead of helper
9+
510
## 0.1.1 - 2018-02-09
611

712
- $expiration parameter of `sign()` helper now defaults to the value defined in the configuration file when not defined

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ Inspired by [laravel-url-signer](https://github.com/spatie/laravel-url-signer)
66
[![Latest Version on Packagist](https://img.shields.io/packagist/v/dreamonkey/laravel-cloudfront-url-signer.svg?style=flat-square)](https://packagist.org/packages/dreamonkey/laravel-cloudfront-url-signer)
77
[![Total Downloads](https://img.shields.io/packagist/dt/dreamonkey/laravel-cloudfront-url-signer.svg?style=flat-square)](https://packagist.org/packages/dreamonkey/laravel-cloudfront-url-signer)
88

9-
This package can create canned policies signed URLs for CloudFront which expires after a given time. This is done by wrapping the AWS SDK method adding a Laravel-style configuration.
9+
This package can create canned policies signed URLs for CloudFront which expires after a given time. This is done by wrapping the AWS SDK method adding a Laravel-style configuration and accessibility.
1010

1111
This is how you can create signed URL that's valid for 30 days:
1212

1313
```php
14+
// With Facade
1415
CloudFrontUrlSigner::sign('https://myapp.com/resource', 30);
16+
17+
// With helper
18+
sign('https://myapp.com/resource', 30);
1519
```
1620

17-
The output will be compliant with [CloudFront specifications](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-canned-policy.html)
21+
The output is compliant with [CloudFront specifications](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-canned-policy.html)
1822

1923
## Installation
2024

src/CloudFrontUrlSigner.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ public function __construct(CloudFrontClient $cloudFrontClient, string $privateK
5959
* Get a secure URL to a controller action.
6060
*
6161
* @param string $url
62-
* @param \DateTime|int $expiration
62+
* @param \DateTime|int|null $expiration
6363
*
6464
* @return string
6565
* @throws \Dreamonkey\CloudFrontUrlSigner\Exceptions\InvalidExpiration
6666
*/
67-
public function sign(string $url, $expiration): string
67+
public function sign(string $url, $expiration = null): string
6868
{
6969
$resourceKey = Http::createFromString($url);
7070

71-
$expiration = $this->getExpirationTimestamp($expiration);
71+
$expiration = $this->getExpirationTimestamp($expiration ??
72+
config('cloudfront-url-signer.default_expiration_time_in_days'));
7273

7374
return $this->cloudFrontClient->getSignedUrl([
7475
'url' => $resourceKey,

src/CloudFrontUrlSignerServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function boot()
2424
protected function setupConfig(Application $app)
2525
{
2626
$source = realpath(__DIR__ . '/../config/cloudfront-url-signer.php');
27-
$this->publishes([$source => config_path('cloudfront-url-signer.php')]);
27+
$this->publishes([$source => config_path('cloudfront-url-signer.php')], 'config');
2828
$this->mergeConfigFrom($source, 'cloudfront-url-signer');
2929
}
3030

src/helpers.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414
function sign(string $url, $expiration = null): string
1515
{
16-
return app(UrlSigner::class)
17-
->sign($url, $expiration ?? config('cloudfront-url-signer.default_expiration_time_in_days'));
16+
return app(UrlSigner::class)->sign($url, $expiration);
1817
}
1918
}

0 commit comments

Comments
 (0)