From 08208b6f1b62b2ce4c05f74e99526f975acc9f22 Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Mon, 29 Jun 2015 13:35:01 +0300 Subject: [PATCH 1/9] upgrade readme file --- readme.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index ee63ea3..d10ef0d 100755 --- a/readme.md +++ b/readme.md @@ -8,16 +8,16 @@ [![License](https://poser.pugx.org/vinelab/cdn/license)](https://packagist.org/packages/vinelab/cdn) -Content Delivery Network Package for Laravel +##### Content Delivery Network Package for Laravel Upload static assets of your choice to a CDN and have the file paths replaced with full URLs. ----------- - +## Highlights +- Supports Laravel 5.1 @@ -42,7 +42,7 @@ Upload static assets of your choice to a CDN and have the file paths replaced wi ```php 'providers' => array( '...', - 'Vinelab\Cdn\CdnServiceProvider', + Vinelab\Cdn\CdnServiceProvider::class, '...' ), ``` @@ -53,12 +53,12 @@ the `Cdn` class to `CdnFacadeProvider` so you can simply use the `Cdn` facade an ## Configuration Publish the package config file: -```dos + +```bash php artisan vendor:publish vinelab/cdn ``` -and check it out at `app/config/packages/vinelab/cdn/cdn.php` -In case you would like to have environment-based configuration `app/config/packages/vinelab/cdn/[ENV]/cdn.php` +Find it at `config/cdn.php` ### Providers From 181941f468c7c8693fc5a82706eed1449a80034e Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Mon, 29 Jun 2015 15:27:32 +0300 Subject: [PATCH 2/9] fix tests to support AWS v3 --- tests/Vinelab/Cdn/CdnTest.php | 6 +++++- tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/Vinelab/Cdn/CdnTest.php b/tests/Vinelab/Cdn/CdnTest.php index 311b013..269e587 100755 --- a/tests/Vinelab/Cdn/CdnTest.php +++ b/tests/Vinelab/Cdn/CdnTest.php @@ -166,7 +166,11 @@ public function testPushCommand() $m_s3 = M::mock('Aws\S3\S3Client'); $m_s3->shouldReceive('factory') ->andReturn('Aws\S3\S3Client'); - $m_s3->shouldReceive('getCommand'); + $m_command = M::mock('Aws\Command'); + $m_s3->shouldReceive('getCommand') + ->andReturn($m_command); + $m_s3->shouldReceive('execute'); + $p_aws_s3_provider->setS3Client($m_s3); $p_aws_s3_provider->shouldReceive('connect') diff --git a/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php b/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php index 378e580..3fd3e1a 100755 --- a/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php +++ b/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php @@ -47,7 +47,10 @@ public function setUp() $this->m_s3 = M::mock('Aws\S3\S3Client'); $this->m_s3->shouldReceive('factory')->andReturn('Aws\S3\S3Client'); - $this->m_s3->shouldReceive('getCommand'); + $m_command = M::mock('Aws\Command'); + $this->m_s3->shouldReceive('getCommand') + ->andReturn($m_command); + $this->m_s3->shouldReceive('execute'); $this->p_awsS3Provider->setS3Client($this->m_s3); $this->p_awsS3Provider->shouldReceive('connect')->andReturn(true); From c3f56518297164b3765b55d470ad3f9ab83017bc Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Mon, 29 Jun 2015 15:28:12 +0300 Subject: [PATCH 3/9] remove key and secret form the tests --- tests/Vinelab/Cdn/CdnFacadeTest.php | 4 -- tests/Vinelab/Cdn/CdnTest.php | 11 ++--- .../Cdn/Providers/AwsS3ProviderTest.php | 48 +++++++------------ 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/tests/Vinelab/Cdn/CdnFacadeTest.php b/tests/Vinelab/Cdn/CdnFacadeTest.php index ce3a980..b75bd80 100755 --- a/tests/Vinelab/Cdn/CdnFacadeTest.php +++ b/tests/Vinelab/Cdn/CdnFacadeTest.php @@ -27,10 +27,6 @@ public function setUp() 's3' => [ 'region' => 'rrrrrrrrrrrgggggggggnnnnn', 'version' => 'vvvvvvvvssssssssssnnnnnnn', - 'credentials' => [ - 'key' => 'keeeeeeeeeeeeeeeeeeeeeeey', - 'secret' => 'ssssssssccccccccccctttttt', - ], 'buckets' => [ 'bbbuuuucccctttt' => '*', ], diff --git a/tests/Vinelab/Cdn/CdnTest.php b/tests/Vinelab/Cdn/CdnTest.php index 269e587..f9c5905 100755 --- a/tests/Vinelab/Cdn/CdnTest.php +++ b/tests/Vinelab/Cdn/CdnTest.php @@ -85,14 +85,10 @@ public function testPushCommand() 'providers' => [ 'aws' => [ 's3' => [ - 'region' => 'rrrrrrrrrrrgggggggggnnnnn', - 'version' => 'vvvvvvvvssssssssssnnnnnnn', - 'credentials' => [ - 'key' => 'keeeeeeeeeeeeeeeeeeeeeeey', - 'secret' => 'ssssssssccccccccccctttttt', - ], + 'region' => 'us-standard', + 'version' => 'latest', 'buckets' => [ - 'bbbuuuucccctttt' => '*', + 'my-bucket-name' => '*', ], 'acl' => 'public-read', 'cloudfront' => [ @@ -156,6 +152,7 @@ public function testPushCommand() $m_spl_file->shouldReceive('getRealPath') ->andReturn(__DIR__ . '/AwsS3ProviderTest.php'); + // partial mock $p_aws_s3_provider = M::mock('\Vinelab\Cdn\Providers\AwsS3Provider[connect]', array ( $m_console, diff --git a/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php b/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php index 3fd3e1a..40607dc 100755 --- a/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php +++ b/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php @@ -19,7 +19,7 @@ public function setUp() parent::setUp(); $this->url = 'http://www.google.com'; - $this->cdn_url = 'http://ZZZZZZZ.www.google.com/public/css/cool/style.css'; + $this->cdn_url = 'http://my-bucket-name.www.google.com/public/css/cool/style.css'; $this->path = 'public/css/cool/style.css'; $this->path_url = 'http://www.google.com/public/css/cool/style.css'; $this->pased_url = parse_url($this->url); @@ -72,14 +72,10 @@ public function testInitializingObject() 'providers' => [ 'aws' => [ 's3' => [ - 'region' => 'ZZZZZZZ', - 'version' => 'EEEEEEE', - 'credentials' => [ - 'key' => 'XXXXXXX', - 'secret' => 'YYYYYYY', - ], - 'buckets' => [ - 'ZZZZZZZ' => '*', + 'region' => 'us-standard', + 'version' => 'latest', + 'buckets' => [ + 'my-bucket-name' => '*', ], 'acl' => 'public-read', 'cloudfront' => [ @@ -109,14 +105,10 @@ public function testUploadingAssets() 'providers' => [ 'aws' => [ 's3' => [ - 'region' => 'ZZZZZZZ', - 'version' => 'EEEEEEE', - 'credentials' => [ - 'key' => 'XXXXXXX', - 'secret' => 'YYYYYYY', - ], - 'buckets' => [ - 'ZZZZZZZ' => '*', + 'region' => 'us-standard', + 'version' => 'latest', + 'buckets' => [ + 'my-bucket-name' => '*', ], 'acl' => 'public-read', 'cloudfront' => [ @@ -148,14 +140,10 @@ public function testUrlGenerator() 'providers' => [ 'aws' => [ 's3' => [ - 'region' => 'ZZZZZZZ', - 'version' => 'EEEEEEE', - 'credentials' => [ - 'key' => 'XXXXXXX', - 'secret' => 'YYYYYYY', - ], - 'buckets' => [ - 'ZZZZZZZ' => '*', + 'region' => 'us-standard', + 'version' => 'latest', + 'buckets' => [ + 'my-bucket-name' => '*', ], 'acl' => 'public-read', 'cloudfront' => [ @@ -187,13 +175,9 @@ public function testEmptyUrlGenerator() 'providers' => [ 'aws' => [ 's3' => [ - 'region' => 'ZZZZZZZ', - 'version' => 'EEEEEEE', - 'credentials' => [ - 'key' => 'XXXXXXX', - 'secret' => 'YYYYYYY', - ], - 'buckets' => [ + 'region' => 'us-standard', + 'version' => 'latest', + 'buckets' => [ '' => '*', ], 'acl' => 'public-read', From 06b019e626318920372c81f8c6a059371c21cd48 Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Mon, 29 Jun 2015 15:28:49 +0300 Subject: [PATCH 4/9] display the error message when failing to upload --- src/Vinelab/Cdn/Providers/AwsS3Provider.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Vinelab/Cdn/Providers/AwsS3Provider.php b/src/Vinelab/Cdn/Providers/AwsS3Provider.php index 09c0947..b3985eb 100755 --- a/src/Vinelab/Cdn/Providers/AwsS3Provider.php +++ b/src/Vinelab/Cdn/Providers/AwsS3Provider.php @@ -221,8 +221,9 @@ public function upload($assets) $this->s3_client->execute($command); - } catch (S3Exception $e) { - $this->console->writeln("Error while uploading: ($file->getRealpath())"); + } catch(S3Exception $e) { + + $this->console->writeln("" . $e->getMessage() . ""); return false; } From 129d03ed53f4d4ad100848107d7874484ba213a8 Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Mon, 29 Jun 2015 15:29:08 +0300 Subject: [PATCH 5/9] remove key and secret --- src/Vinelab/Cdn/Providers/AwsS3Provider.php | 70 +++++++++------------ 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/src/Vinelab/Cdn/Providers/AwsS3Provider.php b/src/Vinelab/Cdn/Providers/AwsS3Provider.php index b3985eb..3cd4ad2 100755 --- a/src/Vinelab/Cdn/Providers/AwsS3Provider.php +++ b/src/Vinelab/Cdn/Providers/AwsS3Provider.php @@ -1,10 +1,9 @@ [ 'aws' => [ 's3' => [ - 'version' => null, - 'region' => null, - 'credentials' => [ - 'key' => null, - 'secret' => null, - ], - 'buckets' => null, - 'acl' => 'public-read', - 'cloudfront' => [ + 'version' => null, + 'region' => null, + 'buckets' => null, + 'acl' => 'public-read', + 'cloudfront' => [ 'use' => false, 'cdn_url' => null, ], @@ -68,7 +63,7 @@ class AwsS3Provider extends Provider implements ProviderInterface * * @var array */ - protected $rules = [ 'version', 'region', 'key', 'secret', 'buckets', 'url' ]; + protected $rules = ['version', 'region', 'key', 'secret', 'buckets', 'url']; /** * this array holds the parsed configuration to be used across the class @@ -112,9 +107,9 @@ public function __construct( ProviderValidatorInterface $provider_validator, CdnHelperInterface $cdn_helper ) { - $this->console = $console; + $this->console = $console; $this->provider_validator = $provider_validator; - $this->cdn_helper = $cdn_helper; + $this->cdn_helper = $cdn_helper; } /** @@ -132,16 +127,14 @@ public function init($configurations) $this->default = array_merge($this->default, $configurations); $supplier = [ - 'provider_url' => $this->default['url'], - 'threshold' => $this->default['threshold'], - 'version' => $this->default['providers']['aws']['s3']['version'], - 'region' => $this->default['providers']['aws']['s3']['region'], - 'credential_key' => $this->default['providers']['aws']['s3']['credentials']['key'], - 'credential_secret' => $this->default['providers']['aws']['s3']['credentials']['secret'], - 'buckets' => $this->default['providers']['aws']['s3']['buckets'], - 'acl' => $this->default['providers']['aws']['s3']['acl'], - 'cloudfront' => $this->default['providers']['aws']['s3']['cloudfront']['use'], - 'cloudfront_url' => $this->default['providers']['aws']['s3']['cloudfront']['cdn_url'], + 'provider_url' => $this->default['url'], + 'threshold' => $this->default['threshold'], + 'version' => $this->default['providers']['aws']['s3']['version'], + 'region' => $this->default['providers']['aws']['s3']['region'], + 'buckets' => $this->default['providers']['aws']['s3']['buckets'], + 'acl' => $this->default['providers']['aws']['s3']['acl'], + 'cloudfront' => $this->default['providers']['aws']['s3']['cloudfront']['use'], + 'cloudfront_url' => $this->default['providers']['aws']['s3']['cloudfront']['cdn_url'], ]; // check if any required configuration is missed @@ -153,7 +146,8 @@ public function init($configurations) } /** - * Create a cdn instance and create a batch builder instance + * Create an S3 client instance + * (Note: it will read the credentials form the .env file) * * @return bool */ @@ -162,17 +156,13 @@ public function connect() try { // Instantiate an S3 client $this->setS3Client(new S3Client([ - 'version' => $this->supplier['version'], - 'region' => $this->supplier['region'], - 'credentials' => [ - 'key' => $this->supplier['credential_key'], - 'secret' => $this->supplier['credential_secret'] - ] + 'version' => $this->supplier['version'], + 'region' => $this->supplier['region'], ] ) ); - } catch (\Exception $e) { + } catch(\Exception $e) { return false; } @@ -192,7 +182,7 @@ public function upload($assets) // connect before uploading $connected = $this->connect(); - if ( ! $connected) { + if (!$connected) { return false; } @@ -218,7 +208,7 @@ public function upload($assets) 'MetaData' => $this->default['providers']['aws']['s3']['metadata'], "Expires" => $this->default['providers']['aws']['s3']['expires'] ]); - +// var_dump(get_class($command));exit(); $this->s3_client->execute($command); } catch(S3Exception $e) { @@ -246,7 +236,7 @@ public function emptyBucket() // connect before uploading $connected = $this->connect(); - if ( ! $connected) { + if (!$connected) { return false; } @@ -262,7 +252,7 @@ public function emptyBucket() ]); // Check if the bucket is already empty - if ( ! $contents['Contents']) { + if (!$contents['Contents']) { $this->console->writeln('The bucket ' . $this->getBucket() . ' is already empty.'); return true; @@ -276,7 +266,7 @@ public function emptyBucket() $empty->delete(); - } catch (S3Exception $e) { + } catch(S3Exception $e) { $this->console->writeln("" . $e->getMessage() . ""); return false; @@ -306,7 +296,7 @@ public function urlGenerator($path) $url = $this->cdn_helper->parseUrl($this->getUrl()); $bucket = $this->getBucket(); - $bucket = ( ! empty( $bucket ) ) ? $bucket . '.' : ''; + $bucket = (!empty($bucket)) ? $bucket . '.' : ''; return $url['scheme'] . '://' . $bucket . $url['host'] . '/' . $path; } @@ -332,7 +322,7 @@ public function getUrl() */ public function getCloudFront() { - if ( ! is_bool($cloudfront = $this->cloudfront)) { + if (!is_bool($cloudfront = $this->cloudfront)) { return false; } @@ -370,7 +360,7 @@ public function getBucket() */ public function __get($attr) { - return isset( $this->supplier[$attr] ) ? $this->supplier[$attr] : null; + return isset($this->supplier[$attr]) ? $this->supplier[$attr] : null; } } From 5d48c3bca7e6a163525ef8f94f82c088a5c0d5cf Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Mon, 29 Jun 2015 16:01:51 +0300 Subject: [PATCH 6/9] enhance config file documentation and the reamdme file --- readme.md | 202 +++++++++++++++++++++++---------------------- src/config/cdn.php | 57 ++++++++----- 2 files changed, 138 insertions(+), 121 deletions(-) diff --git a/readme.md b/readme.md index d10ef0d..545e357 100755 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# CDN Assets Manager +# Laravel CDN Assets Manager [![Total Downloads](https://poser.pugx.org/vinelab/cdn/downloads)](https://packagist.org/packages/vinelab/cdn) [![Latest Stable Version](https://poser.pugx.org/vinelab/cdn/v/stable)](https://packagist.org/packages/vinelab/cdn) @@ -10,191 +10,182 @@ ##### Content Delivery Network Package for Laravel -Upload static assets of your choice to a CDN and have the file paths replaced with full URLs. - - +The package provides the devloper the ability to upload his assets (or any public file) to a CDN with a single artisan command. +And then it allows him to switch between the local and the online version of the files, for develpoment and production purposes. ## Highlights -- Supports Laravel 5.1 - - +- Amazon Web Services - S3 +- Supports Laravel 5.1 +- Artisan command to upload content to CDN +- Simple Facade to access CDN assets -## Install +## Installation -### Via Composer +#### Via Composer -- Add the package to your `composer.json` and run `composer update` +A. Require `vinelab/cdn` in your project: - ```json - { - "require": { - "vinelab/cdn": "*" - } - } - ``` +```bash +composer require vinelab/cdn:* +``` -- Add the service provider to `app/config/app.php`: +*Since this is a Laravel package we need to register the service provider:* - ```php - 'providers' => array( - '...', - Vinelab\Cdn\CdnServiceProvider::class, - '...' - ), - ``` +Add the service provider to `app/config/app.php`: -The service provider will register all the required classes for this package and will also alias -the `Cdn` class to `CdnFacadeProvider` so you can simply use the `Cdn` facade anywhere in your app. +```php +'providers' => array( + //... + Vinelab\Cdn\CdnServiceProvider::class, +), +``` ## Configuration -Publish the package config file: +First you need to publish the package config file: ```bash php artisan vendor:publish vinelab/cdn ``` -Find it at `config/cdn.php` - -### Providers +You can find it at `config/cdn.php` -Supported Providers: -- Amazon Web Services - S3 (Default) - -#### Default Provider +##### Default Provider ```php 'default' => 'AwsS3', ``` -#### CDN Provider Setup +##### CDN Provider Configuration ```php - 'aws' => [ - - 's3' => [ - - 'version' => 'latest', - - 'region' => '', - - 'credentials' => [ - 'key' => '', - 'secret' => '', - ], - - 'buckets' => [ - 'my-backup-bucket' => '*', - ] +'aws' => [ + + 's3' => [ + + 'version' => 'latest', + 'region' => '', + + 'buckets' => [ + 'my-backup-bucket' => '*', ] - ], + ] +], ``` -##### Multiple Buckets +###### Multiple Buckets ```php 'buckets' => [ 'my-default-bucket' => '*', - 'js-bucket' => ['public/js'], - 'css-bucket' => ['public/css'], - '...' + + // 'js-bucket' => ['public/js'], + // 'css-bucket' => ['public/css'], + // ... ] ``` -### Files & Directories +#### Files & Directories -#### Include +###### Include: Specify directories, extensions, files and patterns to be uploaded. ```php - 'include' => [ - 'directories' => ['public/dist'], - 'extensions' => ['.js', '.css', '.yxz'], - 'patterns' => ['**/*.coffee'], - ], +'include' => [ + 'directories' => ['public/dist'], + 'extensions' => ['.js', '.css', '.yxz'], + 'patterns' => ['**/*.coffee'], +], ``` -#### Exclude +###### Exclude: Specify what to be ignored. ```php - 'exclude' => [ - 'directories' => ['public/uploads'], - 'files' => [''], - 'extensions' => ['.TODO', '.txt'], - 'patterns' => ['src/*', '.idea/*'], - 'hidden' => true, // ignore hidden files - ], +'exclude' => [ + 'directories' => ['public/uploads'], + 'files' => [''], + 'extensions' => ['.TODO', '.txt'], + 'patterns' => ['src/*', '.idea/*'], + 'hidden' => true, // ignore hidden files +], ``` -#### URL +##### URL Set the CDN URL: ```php - 'url' => 'https://s3.amazonaws.com', +'url' => 'https://s3.amazonaws.com', ``` -#### Threshold -Determines how many files to be uploaded concurrently. +##### Bypass -> Will clear the buffer when the `threshold` has been reached, be careful when setting this to a high value -not to exceed what you have allowed in your PHP configuration. +To load your LOCAL assets for testing or during development, set the `bypass` option to `true`: ```php - 'threshold' => 10, +'bypass' => true, ``` -#### Bypass +##### Cloudfront Support + +```php +'cloudfront' => [ + 'use' => false, + 'cdn_url' => '' +], +``` -To load your local assets (not the CDN assets) for testing or during development, set the `bypass` option to `true`: + +##### Other Configurations +You can always refer to the AWS S3 Docuemntation for more details: [aws-sdk-php](http://docs.aws.amazon.com/aws-sdk-php/v3/guide/) ```php - 'bypass' => true, +'acl' => 'public-read', +'metadata' => [ ], +'expires' => gmdate("D, d M Y H:i:s T", strtotime("+5 years")), +'cache-control' => 'max-age=2628000', ``` + ## Usage -### Push +#### Push Upload your assets with -```dos +```bash php artisan cdn:push ``` -### Empty +#### Empty Delete all of your assets remotely with -```dos +```bash php artisan cdn:empty ``` -### Load Assets -Now you can use the facade `Cdn` to call the `Cdn::asset()` function. -Note: the `asset` works the same as the Laravel `asset` it start looking for assets in the `public/` directory: +#### Load Assets + +Use the facade `Cdn` to call the `Cdn::asset()` function. + +*Note: the `asset` works the same as the Laravel `asset` it start looking for assets in the `public/` directory:* ```blade - {{Cdn::asset('assets/js/main.js')}} - // https://js-bucket.s3.amazonaws.com/public/assets/js/main.js +{{Cdn::asset('assets/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/assets/js/main.js - {{Cdn::asset('assets/css/main.css')}} - // https://css-bucket.s3.amazonaws.com/public/assets/css/main.css +{{Cdn::asset('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/assets/css/style.css ``` -If you want to use a file from outside the `public/` directory anywhere in `app/` you can use the `Cdn::path()` function to do that: +To use a file from outside the `public/` directory, anywhere in `app/` use the `Cdn::path()` function: ```blade - {{Cdn::path('public/assets/js/main.js')}} - // https://js-bucket.s3.amazonaws.com/public/assets/js/main.js - - {{Cdn::path('private/something/file.txt')}} - // https://css-bucket.s3.amazonaws.com/private/something/file.txt +{{Cdn::path('private/something/file.txt')}} // example result: https://css-bucket.s3.amazonaws.com/private/something/file.txt ``` @@ -208,6 +199,19 @@ If you want to use a file from outside the `public/` directory anywhere in `app/ +## Test + +To run the tests, run the following command from the project folder. + +```bash +$ ./vendor/bin/phpunit +``` + +## Support + +[On Github](https://github.com/Vinelab/cdn/issues) + + ## Contributing Please see [CONTRIBUTING](https://github.com/Vinelab/cdn/blob/master/CONTRIBUTING.md) for details. diff --git a/src/config/cdn.php b/src/config/cdn.php index 845a831..e990861 100755 --- a/src/config/cdn.php +++ b/src/config/cdn.php @@ -15,7 +15,7 @@ | Default: false | */ - 'bypass' => false, + 'bypass' => false, /* |-------------------------------------------------------------------------- @@ -28,7 +28,7 @@ | Supported provider: Amazon S3 (AwsS3) | */ - 'default' => 'AwsS3', + 'default' => 'AwsS3', /* |-------------------------------------------------------------------------- @@ -38,7 +38,7 @@ | Set your CDN url, [without the bucket name] | */ - 'url' => 'https://s3.amazonaws.com', + 'url' => 'https://s3.amazonaws.com', /* |-------------------------------------------------------------------------- @@ -63,8 +63,9 @@ | Of course, examples of configuring each provider platform that is | supported by Laravel is shown below to make development simple. | - | version: 'latest' means versioning is not enabled, you can replace it - | by your version to enabled it. + | Note: Credentials must be set in the .env file: + | AWS_ACCESS_KEY_ID + | AWS_SECRET_ACCESS_KEY | */ 'providers' => [ @@ -73,14 +74,27 @@ 's3' => [ - 'version' => 'latest', - - 'region' => '', + /* + |-------------------------------------------------------------------------- + | Web Service Version + |-------------------------------------------------------------------------- + | + | The version of the web service to utilize. + | http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/configuration.html#version + | + */ + 'version' => 'latest', - 'credentials' => [ - 'key' => '', - 'secret' => '', - ], + /* + |-------------------------------------------------------------------------- + | Region to Connect + |-------------------------------------------------------------------------- + | + | List of available regions: + | http://docs.aws.amazon.com/general/latest/gr/rande.html#awsconfig_region + | + */ + 'region' => '', /* |-------------------------------------------------------------------------- @@ -99,8 +113,9 @@ 'buckets' => [ 'bucket-name' => '*', - // 'your-js-bucket-name-here' => ['public/js'], - // 'your-css-bucket-name-here' => ['public/css'], + // examples: + // 'your-js-bucket-name-here' => ['public/js'], + // 'your-css-bucket-name-here' => ['public/css'], ], /* @@ -115,7 +130,7 @@ | bucket-owner-read, bucket-owner-full-control, log-delivery-write | */ - 'acl' => 'public-read', + 'acl' => 'public-read', /* |-------------------------------------------------------------------------- @@ -128,7 +143,7 @@ | */ 'cloudfront' => [ - 'use' => false, + 'use' => false, 'cdn_url' => '' ], @@ -140,7 +155,7 @@ | Add metadata to each S3 file | */ - 'metadata' => [ ], + 'metadata' => [ ], /* |-------------------------------------------------------------------------- @@ -150,7 +165,7 @@ | Add expiry data to file | */ - 'expires' => gmdate("D, d M Y H:i:s T", strtotime("+5 years")), + 'expires' => gmdate("D, d M Y H:i:s T", strtotime("+5 years")), /* |-------------------------------------------------------------------------- @@ -165,10 +180,8 @@ ], ], -// 'cloudflare' => [ -// 'key' => '', -// 'secret' => '', -// ], + + ], /* From e59035926c5912e8a5945066c89982a8d20a17e8 Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Mon, 29 Jun 2015 16:06:10 +0300 Subject: [PATCH 7/9] simpe read me update --- readme.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 545e357..fb1dbf5 100755 --- a/readme.md +++ b/readme.md @@ -27,7 +27,7 @@ And then it allows him to switch between the local and the online version of th #### Via Composer -A. Require `vinelab/cdn` in your project: +Require `vinelab/cdn` in your project: ```bash composer require vinelab/cdn:* @@ -146,7 +146,6 @@ To load your LOCAL assets for testing or during development, set the `bypass` op ##### Other Configurations -You can always refer to the AWS S3 Docuemntation for more details: [aws-sdk-php](http://docs.aws.amazon.com/aws-sdk-php/v3/guide/) ```php 'acl' => 'public-read', @@ -155,17 +154,19 @@ You can always refer to the AWS S3 Docuemntation for more details: [aws-sdk-php] 'cache-control' => 'max-age=2628000', ``` +You can always refer to the AWS S3 Docuemntation for more details: [aws-sdk-php](http://docs.aws.amazon.com/aws-sdk-php/v3/guide/) + ## Usage #### Push -Upload your assets with +Upload assets ```bash php artisan cdn:push ``` #### Empty -Delete all of your assets remotely with +Delete all of your assets remotely ```bash php artisan cdn:empty ``` From a4b5f79449989ff91715ce968f9d72cefcc35029 Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Mon, 29 Jun 2015 16:21:09 +0300 Subject: [PATCH 8/9] include the AWS Credentials details to the doc --- readme.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index fb1dbf5..0c8acc6 100755 --- a/readme.md +++ b/readme.md @@ -10,9 +10,8 @@ ##### Content Delivery Network Package for Laravel -The package provides the devloper the ability to upload his assets (or any public file) to a CDN with a single artisan command. -And then it allows him to switch between the local and the online version of the files, for develpoment and production purposes. - +The package provides the developer the ability to upload his assets (or any public file) to a CDN with a single artisan command. +And then it allows him to switch between the local and the online version of the files, for development and production purposes. ## Highlights @@ -46,7 +45,16 @@ Add the service provider to `app/config/app.php`: ## Configuration -First you need to publish the package config file: +Set AWS Credentials to the `.env` file. + +*Note: you should have an `.env` file at the project root directory of your project, to hold your sensitive information.* + +```bash +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +``` + +Publish the package config file: ```bash php artisan vendor:publish vinelab/cdn From 205ba24a760a6c1dd0e1cdbd5416fdf4246ea81b Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Mon, 29 Jun 2015 16:23:54 +0300 Subject: [PATCH 9/9] fix read me file --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 0c8acc6..9714ce1 100755 --- a/readme.md +++ b/readme.md @@ -45,9 +45,9 @@ Add the service provider to `app/config/app.php`: ## Configuration -Set AWS Credentials to the `.env` file. +Set the Credentials in the `.env` file. -*Note: you should have an `.env` file at the project root directory of your project, to hold your sensitive information.* +*Note: you must have an `.env` file at the project root, to hold your sensitive information.* ```bash AWS_ACCESS_KEY_ID= @@ -162,7 +162,7 @@ To load your LOCAL assets for testing or during development, set the `bypass` op 'cache-control' => 'max-age=2628000', ``` -You can always refer to the AWS S3 Docuemntation for more details: [aws-sdk-php](http://docs.aws.amazon.com/aws-sdk-php/v3/guide/) +You can always refer to the AWS S3 Documentation for more details: [aws-sdk-php](http://docs.aws.amazon.com/aws-sdk-php/v3/guide/) ## Usage