diff --git a/composer.json b/composer.json index 491a224..6704f8b 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "php-opencloud/openstack": "^2.0", "illuminate/support": "^5.4", "league/flysystem": "^1.0", - "nimbusoft/flysystem-openstack-swift": "^0.2.0" + "nimbusoft/flysystem-openstack-swift": "^0.2.0", + "nesbot/carbon": "^1.22" }, "require-dev": { "phpunit/phpunit": "^5.5", diff --git a/src/OVHSwiftAdapter.php b/src/OVHSwiftAdapter.php index 951778f..4c46213 100644 --- a/src/OVHSwiftAdapter.php +++ b/src/OVHSwiftAdapter.php @@ -2,6 +2,7 @@ namespace Sausin\LaravelOvh; +use Carbon\Carbon; use BadMethodCallException; use OpenStack\ObjectStore\v1\Service; use OpenStack\Common\Error\BadResponseError; @@ -89,18 +90,18 @@ public function getUrlConfirm($path) * Generate a temporary URL for private containers. * * @param string $path - * @param int $expiration + * @param Carbon $expiration * @param array $options * @return string */ - public function getTemporaryUrl($path, $expiration = 60 * 60, $options) + public function getTemporaryUrl($path, $expiration, $options = []) { if (! is_array($this->urlVars) || count($this->urlVars) !== 4) { throw new BadMethodCallException('Insufficient Url Params', 1); } // expiry is relative to current time - $expiresAt = (int) (time() + $expiration); + $expiresAt = $expiration instanceof Carbon ? $expiration->timestamp : (int) (time() + 60 * 60); // get the method $method = isset($options['method']) ? $options['method'] : 'GET'; diff --git a/tests/OVHSwiftAdapterTest.php b/tests/OVHSwiftAdapterTest.php index d5a52c1..635bc1f 100644 --- a/tests/OVHSwiftAdapterTest.php +++ b/tests/OVHSwiftAdapterTest.php @@ -3,6 +3,7 @@ namespace Sausin\LaravelOvh\Tests; use Mockery; +use Carbon\Carbon; use League\Flysystem\Config; use Sausin\LaravelOvh\OVHSwiftAdapter; @@ -59,7 +60,7 @@ public function testTemporaryUrlMethod() $this->object->shouldNotReceive('retrieve'); $this->container->shouldNotReceive('getObject'); - $url = $this->adapter->getTemporaryUrl('hello.jpg'); + $url = $this->adapter->getTemporaryUrl('hello.jpg', Carbon::now()->addMinutes(10)); $this->assertNotNull($url); }