Skip to content

Commit

Permalink
Merge pull request #32 from Vinelab/develop
Browse files Browse the repository at this point in the history
Add bypass option
  • Loading branch information
Mulkave committed Oct 13, 2014
2 parents 921cdfe + 5708bc8 commit 0611830
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ not to exceed what you have allowed in your PHP configuration.
'threshold' => 10,
```

#### Bypass

To load your local assets (not the CDN assets) for testing or during development, set the `bypass` option to `true`:

```php
'bypass' => true,
```
## Usage

### Push
Expand Down
1 change: 1 addition & 0 deletions src/Vinelab/Cdn/Cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function push()
// Initialize an instance of the asset holder to read the configurations
// then call the read(), to return all the allowed assets as a collection of files objects
$assets = $this->finder->read($this->asset_holder->init($configurations));

// store the returned assets in the instance of the asset holder as collection of paths
$this->asset_holder->setAssets($assets);

Expand Down
17 changes: 14 additions & 3 deletions src/Vinelab/Cdn/CdnFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
*/
class CdnFacade implements CdnFacadeInterface{

/**
* @var array
*/
protected $configurations;

/**
* @var Contracts\ProviderFactoryInterface
*/
Expand Down Expand Up @@ -90,7 +95,8 @@ public function path($path)
}

/**
* responsible of preparing the path before generating the url
* check if package is surpassed or not then
* prepare the path before generating the url
*
* @param $path
* @param $prepend
Expand All @@ -100,6 +106,11 @@ public function path($path)
*/
private function generateUrl($path, $prepend = '')
{
// if the package is surpassed, then return the same $path
// to load the asset from the localhost
if ( isset($this->configurations['bypass']) and $this->configurations['bypass'] )
return $path;

if ( ! isset($path))
throw new EmptyPathException('Path does not exist.');

Expand All @@ -120,10 +131,10 @@ private function generateUrl($path, $prepend = '')
private function init()
{
// return the configurations from the config file
$configurations = $this->helper->getConfigurations();
$this->configurations = $this->helper->getConfigurations();

// return an instance of the corresponding Provider concrete according to the configuration
$this->provider = $this->provider_factory->create($configurations);
$this->provider = $this->provider_factory->create($this->configurations);
}

}
19 changes: 18 additions & 1 deletion src/config/cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

return [


/*
|--------------------------------------------------------------------------
| Bypass loading assets from the CDN
|--------------------------------------------------------------------------
|
| This option determines whether to load the assets from localhost or from
| the CDN server. (this is useful during development).
| Set it to "true" to load from localhost, or set it to "false" to load
| from the CDN (on production).
|
| Default: false
|
*/

'bypass' => false,

/*
|--------------------------------------------------------------------------
| Default CDN provider
Expand Down Expand Up @@ -75,7 +92,7 @@
|
*/
'buckets' => [
'bucket-name-here' => '*',
'bucket-name' => '*',
// 'your-js-bucket-name-here' => ['public/js'],
// 'your-css-bucket-name-here' => ['public/css'],
],
Expand Down

0 comments on commit 0611830

Please sign in to comment.