Skip to content

Commit df9b61f

Browse files
authored
Merge pull request #18 from publiux/development
New version 2. Laravel 5.5 support added.
2 parents 07212db + 1a542fe commit df9b61f

File tree

9 files changed

+301
-379
lines changed

9 files changed

+301
-379
lines changed
File renamed without changes.

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ php:
44
- 5.5
55
- 5.6
66
- 7.0
7+
- 7.1
78
- hhvm
89

910
matrix:
@@ -22,4 +23,4 @@ after_script:
2223

2324
notifications:
2425
slack:
25-
secure: GLAz8cc60i+a7DiXrFqoThKPaSOpNbcCiqjSur8LuBPCtxWMfBFEKsmE7iweAe5fLUTffx4TbMbMd38LS/3hwpt5oYOoQBQ8IQDNtFJ7rbLkGtC6SI6lrPTWdBDfTyHevG4aOJZCiFe5+Tajvj2CWD+YAMcGaCn6s8IVLU5NoPw=
26+
secure: GLAz8cc60i+a7DiXrFqoThKPaSOpNbcCiqjSur8LuBPCtxWMfBFEKsmE7iweAe5fLUTffx4TbMbMd38LS/3hwpt5oYOoQBQ8IQDNtFJ7rbLkGtC6SI6lrPTWdBDfTyHevG4aOJZCiFe5+Tajvj2CWD+YAMcGaCn6s8IVLU5NoPw=

composer.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
],
2222
"require": {
2323
"php": ">=5.5.9",
24-
"illuminate/support": "~5.0",
25-
"illuminate/config": "~5.0",
26-
"symfony/finder": "2.8.*|3.0.*",
27-
"symfony/console": "2.8.*|3.0.*",
28-
"aws/aws-sdk-php": "~3.0"
24+
"illuminate/support": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*",
25+
"illuminate/config": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*",
26+
"symfony/finder": "2.*|3.*",
27+
"symfony/console": "2.*|3.*",
28+
"aws/aws-sdk-php": "~3.0"
2929
},
3030
"require-dev": {
3131
"phpunit/phpunit": "~4.0",
@@ -36,9 +36,19 @@
3636
"tests/TestCase.php",
3737
"src/Publiux/laravelcdn/Exceptions"
3838
],
39-
"psr-0": {
39+
"psr-0": {
4040
"Publiux\\laravelcdn\\": "src/"
4141
}
4242
},
43+
"extra": {
44+
"laravel": {
45+
"providers": [
46+
"Publiux\\laravelcdn\\CDNServiceProvider"
47+
],
48+
"aliases": {
49+
"CDN": "Publiux\\laravelcdn\\Facades\\CdnFacadeAccessor"
50+
}
51+
}
52+
},
4353
"minimum-stability": "stable"
4454
}

readme.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
##### Content Delivery Network Package for Laravel
1111

12-
The package provides the developer the ability to upload his assets (or any public file) to a CDN with a single artisan command.
13-
And then it allows him to switch between the local and the online version of the files.
12+
The package provides the developer the ability to upload their assets (or any public file) to a CDN with a single artisan command.
13+
And then it allows them to switch between the local and the online version of the files.
1414

1515
###### Fork From [Vinelab/cdn](https://github.com/Vinelab/cdn)
1616
This project has been forked from https://github.com/Vinelab/cdn. All credit for the original work goes there.
1717

1818
#### Laravel Support
19-
- This fork support Laravel 5.2. (`master`).
20-
- As new versions of Laravel are released, new branches will be created to create compatibility if there are breaking changes in laravel.
19+
- This fork supports Laravel 5.2 up to an including Laravel 5.5 (`master`).
20+
- Laravel 5.5 is supported, as is package auto-discovery.
2121

2222
## Highlights
2323

@@ -39,24 +39,25 @@ This project has been forked from https://github.com/Vinelab/cdn. All credit for
3939
Require `publiux/laravelcdn` in your project:
4040

4141
```bash
42-
composer require publiux/laravelcdn
42+
composer require "publiux/laravelcdn:~2.0"
4343
```
4444

45-
*Since this is a Laravel package we need to register the service provider:*
45+
*If you are using Laravel 5.4 or below, you need to register the service provider:*
4646

47-
Add the service provider to `config/app.php`:
47+
Laravel 5.4 and below: Add the service provider to `config/app.php`:
4848

4949
```php
5050
'providers' => array(
5151
//...
5252
Publiux\laravelcdn\CdnServiceProvider::class,
5353
),
5454
```
55+
*If you are using Laravel 5.5, there is no need to register the service provider as this package is automatically discovered.*
5556

5657
Publish the package config file:
5758

5859
```bash
59-
php artisan vendor:publish
60+
php artisan vendor:publish --provider 'Publiux\laravelcdn\CdnServiceProvider'
6061
```
6162

6263
## Environment Configuration
@@ -227,6 +228,18 @@ Use the facade `Cdn` to call the `Cdn::asset()` function.
227228
228229
{{Cdn::asset('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/assets/css/style.css
229230
```
231+
*Note: the `elixir` works the same as the Laravel `elixir` it loads the manifest.json file from build folder and choose the correct file revision generated by gulp:*
232+
```blade
233+
{{Cdn::elixir('assets/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/build/assets/js/main-85cafe36ff.js
234+
235+
{{Cdn::elixir('assets/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/build/assets/css/style-2d558139f2.css
236+
```
237+
*Note: the `mix` works the same as the Laravel 5.4 `mix` it loads the mix-manifest.json file from public folder and choose the correct file revision generated by webpack:*
238+
```blade
239+
{{Cdn::mix('/js/main.js')}} // example result: https://js-bucket.s3.amazonaws.com/public/js/main-85cafe36ff.js
240+
241+
{{Cdn::mix('/css/style.css')}} // example result: https://css-bucket.s3.amazonaws.com/public/css/style-2d558139f2.css
242+
```
230243

231244
To use a file from outside the `public/` directory, anywhere in `app/` use the `Cdn::path()` function:
232245

src/Publiux/laravelcdn/CdnFacade.php

Lines changed: 71 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -65,48 +65,22 @@ public function __construct(
6565
}
6666

6767
/**
68-
* this function will be called from the 'views' using the
69-
* 'Cdn' facade {{Cdn::asset('')}} to convert the path into
70-
* it's CDN url.
71-
*
72-
* @param $path
73-
*
74-
* @throws Exceptions\EmptyPathException
75-
*
76-
* @return mixed
68+
* Read the configuration file and pass it to the provider factory
69+
* to return an object of the default provider specified in the
70+
* config file.
7771
*/
78-
public function asset($path)
72+
private function init()
7973
{
80-
// if asset always append the public/ dir to the path (since the user should not add public/ to asset)
81-
return $this->generateUrl($path, 'public/');
82-
}
74+
// return the configurations from the config file
75+
$this->configurations = $this->helper->getConfigurations();
8376

84-
/**
85-
* this function will be called from the 'views' using the
86-
* 'Cdn' facade {{Cdn::elixir('')}} to convert the elixir generated file path into
87-
* it's CDN url.
88-
*
89-
* @param $path
90-
*
91-
* @throws Exceptions\EmptyPathException, \InvalidArgumentException
92-
*
93-
* @return mixed
94-
*/
95-
public function elixir($path)
96-
{
97-
static $manifest = null;
98-
if (is_null($manifest)) {
99-
$manifest = json_decode(file_get_contents(public_path('build/rev-manifest.json')), true);
100-
}
101-
if (isset($manifest[$path])) {
102-
return $this->generateUrl('build/'.$manifest[$path], 'public/');
103-
}
104-
throw new \InvalidArgumentException("File {$path} not defined in asset manifest.");
77+
// return an instance of the corresponding Provider concrete according to the configuration
78+
$this->provider = $this->provider_factory->create($this->configurations);
10579
}
10680

10781
/**
10882
* this function will be called from the 'views' using the
109-
* 'Cdn' facade {{Cdn::path('')}} to convert the path into
83+
* 'Cdn' facade {{Cdn::asset('')}} to convert the path into
11084
* it's CDN url.
11185
*
11286
* @param $path
@@ -115,9 +89,10 @@ public function elixir($path)
11589
*
11690
* @return mixed
11791
*/
118-
public function path($path)
92+
public function asset($path)
11993
{
120-
return $this->generateUrl($path);
94+
// if asset always append the public/ dir to the path (since the user should not add public/ to asset)
95+
return $this->generateUrl($path, 'public/');
12196
}
12297

12398
/**
@@ -157,16 +132,67 @@ private function generateUrl($path, $prepend = '')
157132
}
158133

159134
/**
160-
* Read the configuration file and pass it to the provider factory
161-
* to return an object of the default provider specified in the
162-
* config file.
135+
* this function will be called from the 'views' using the
136+
* 'Cdn' facade {{Cdn::mix('')}} to convert the Laravel 5.4 webpack mix
137+
* generated file path into it's CDN url.
138+
*
139+
* @param $path
140+
*
141+
* @return mixed
142+
*
143+
* @throws Exceptions\EmptyPathException, \InvalidArgumentException
163144
*/
164-
private function init()
145+
public function mix($path)
165146
{
166-
// return the configurations from the config file
167-
$this->configurations = $this->helper->getConfigurations();
147+
static $manifest = null;
148+
if (is_null($manifest)) {
149+
$manifest = json_decode(file_get_contents(public_path('mix-manifest.json')), true);
150+
}
151+
if (isset($manifest['/' . $path])) {
152+
return $this->generateUrl($manifest['/' . $path], 'public/');
153+
}
154+
if (isset($manifest[$path])) {
155+
return $this->generateUrl($manifest[$path], 'public/');
156+
}
157+
throw new \InvalidArgumentException("File {$path} not defined in asset manifest.");
158+
}
168159

169-
// return an instance of the corresponding Provider concrete according to the configuration
170-
$this->provider = $this->provider_factory->create($this->configurations);
160+
/**
161+
* this function will be called from the 'views' using the
162+
* 'Cdn' facade {{Cdn::elixir('')}} to convert the elixir generated file path into
163+
* it's CDN url.
164+
*
165+
* @param $path
166+
*
167+
* @throws Exceptions\EmptyPathException, \InvalidArgumentException
168+
*
169+
* @return mixed
170+
*/
171+
public function elixir($path)
172+
{
173+
static $manifest = null;
174+
if (is_null($manifest)) {
175+
$manifest = json_decode(file_get_contents(public_path('build/rev-manifest.json')), true);
176+
}
177+
if (isset($manifest[$path])) {
178+
return $this->generateUrl('build/' . $manifest[$path], 'public/');
179+
}
180+
throw new \InvalidArgumentException("File {$path} not defined in asset manifest.");
181+
}
182+
183+
/**
184+
* this function will be called from the 'views' using the
185+
* 'Cdn' facade {{Cdn::path('')}} to convert the path into
186+
* it's CDN url.
187+
*
188+
* @param $path
189+
*
190+
* @throws Exceptions\EmptyPathException
191+
*
192+
* @return mixed
193+
*/
194+
public function path($path)
195+
{
196+
return $this->generateUrl($path);
171197
}
172198
}

src/Publiux/laravelcdn/CdnServiceProvider.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ public function register()
9595

9696
// register the commands:
9797
//-----------------------
98-
$this->app['cdn.push'] = $this->app->share(function () {
99-
return $this->app->make('Publiux\laravelcdn\Commands\PushCommand');
98+
$this->app->singleton('cdn.push', function ($app) {
99+
return $app->make('Publiux\laravelcdn\Commands\PushCommand');
100100
});
101101

102102
$this->commands('cdn.push');
103103

104-
$this->app['cdn.empty'] = $this->app->share(function () {
105-
return $this->app->make('Publiux\laravelcdn\Commands\EmptyCommand');
104+
$this->app->singleton('cdn.empty', function ($app) {
105+
return $app->make('Publiux\laravelcdn\Commands\EmptyCommand');
106106
});
107107

108108
$this->commands('cdn.empty');
@@ -111,15 +111,15 @@ public function register()
111111
//-----------------
112112

113113
// Register 'CdnFacade' instance container to our CdnFacade object
114-
$this->app['cdn'] = $this->app->share(function () {
115-
return $this->app->make('Publiux\laravelcdn\CdnFacade');
114+
$this->app->singleton('CDN', function ($app) {
115+
return $app->make('Publiux\laravelcdn\CdnFacade');
116116
});
117117

118118
// Shortcut so developers don't need to add an Alias in app/config/app.php
119-
$this->app->booting(function () {
120-
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
121-
$loader->alias('Cdn', 'Publiux\laravelcdn\Facades\CdnFacadeAccessor');
122-
});
119+
// $this->app->booting(function () {
120+
// $loader = \Illuminate\Foundation\AliasLoader::getInstance();
121+
// $loader->alias('Cdn', 'Publiux\laravelcdn\Facades\CdnFacadeAccessor');
122+
// });
123123
}
124124

125125
/**

src/Publiux/laravelcdn/Facades/CdnFacadeAccessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class CdnFacadeAccessor extends Facade
2020
*/
2121
protected static function getFacadeAccessor()
2222
{
23-
return 'cdn';
23+
return 'CDN';
2424
}
2525
}

0 commit comments

Comments
 (0)