• Stars
    star
    212
  • Rank 186,122 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CDN Assets Manager Package for Laravel.

Laravel CDN Assets Manager

Total Downloads Latest Stable Version Latest Unstable Version Build Status Scrutinizer Code Quality License

Content Delivery Network Package for Laravel

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.

Laravel Support

  • For Laravel 5.1 use the latest realease (master).
  • For Laravel 4.2 use the realease v1.0.1 Last suport for L 4.2

Highlights

  • Amazon Web Services - S3
  • Artisan command to upload content to CDN
  • Simple Facade to access CDN assets

Installation

Via Composer

Require vinelab/cdn in your project:

composer require vinelab/cdn:*

Since this is a Laravel package we need to register the service provider:

Add the service provider to config/app.php:

'providers' => array(
     //...
     Vinelab\Cdn\CdnServiceProvider::class,
),

Configuration

Set the Credentials in the .env file.

Note: you must have an .env file at the project root, to hold your sensitive information.

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

Publish the package config file:

php artisan vendor:publish vinelab/cdn

You can find it at config/cdn.php

Default Provider
'default' => 'AwsS3',
CDN Provider Configuration
'aws' => [

    's3' => [
    
        'version'   => 'latest',
        'region'    => '',


        'buckets' => [
            'my-backup-bucket' => '*',
        ]
    ]
],
Multiple Buckets
'buckets' => [

    'my-default-bucket' => '*',
    
    // 'js-bucket' => ['public/js'],
    // 'css-bucket' => ['public/css'],
    // ...
]

Files & Directories

Include:

Specify directories, extensions, files and patterns to be uploaded.

'include'    => [
    'directories'   => ['public/dist'],
    'extensions'    => ['.js', '.css', '.yxz'],
    'patterns'      => ['**/*.coffee'],
],
Exclude:

Specify what to be ignored.

'exclude'    => [
    'directories'   => ['public/uploads'],
    'files'         => [''],
    'extensions'    => ['.TODO', '.txt'],
    'patterns'      => ['src/*', '.idea/*'],
    'hidden'        => true, // ignore hidden files
],
URL

Set the CDN URL:

'url' => 'https://s3.amazonaws.com',
HTTP

Set the HTTP parameters:

'http' => '['verify' => path-to-your-pem-certificate-file]',
Bypass

To load your LOCAL assets for testing or during development, set the bypass option to true:

'bypass' => true,
Cloudfront Support
'cloudfront'    => [
    'use' => false,
    'cdn_url' => ''
],
Other Configurations
'acl'           => 'public-read',
'metadata'      => [ ],
'expires'       => gmdate("D, d M Y H:i:s T", strtotime("+5 years")),
'cache-control' => 'max-age=2628000',

You can always refer to the AWS S3 Documentation for more details: aws-sdk-php

Usage

Push

Upload assets to CDN

php artisan cdn:push

Empty

Delete assets from CDN

php artisan cdn:empty

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:

{{Cdn::asset('assets/js/main.js')}}        // example result: https://js-bucket.s3.amazonaws.com/public/assets/js/main.js

{{Cdn::asset('assets/css/style.css')}}        // example result: https://css-bucket.s3.amazonaws.com/public/assets/css/style.css

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:

{{Cdn::elixir('assets/js/main.js')}}        // example result: https://js-bucket.s3.amazonaws.com/public/build/assets/js/main-85cafe36ff.js

{{Cdn::elixir('assets/css/style.css')}}        // example result: https://css-bucket.s3.amazonaws.com/public/build/assets/css/style-2d558139f2.css

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

{{Cdn::path('private/something/file.txt')}}        // example result: https://css-bucket.s3.amazonaws.com/private/something/file.txt

Test

To run the tests, run the following command from the project folder.

$ ./vendor/bin/phpunit

Support

On Github

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

NeoEloquent

The Neo4j OGM for Laravel
PHP
640
star
2

minion

A Simplified Client for WAMP v2 (Web Application Messaging Protocol) with command line support - PHP WebSocket Made Easy
PHP
122
star
3

tracing-laravel

Distributed tracing (OpenTracing) for Laravel made easy
PHP
77
star
4

url-shortener

Shorten your URL the easy way, with your favourite provider (Bit.ly, Goo.gl, Ow.ly).
PHP
59
star
5

http

A smart, simple and fault-tolerant HTTP client for sending and receiving JSON and XML
PHP
57
star
6

laravel-editor

Markdown Text Editor (WYSIWYG) with social network embeds support and a nifty json output
PHP
53
star
7

RSS

Simple RSS Client
PHP
48
star
8

bowler

RabbitMQ wrapper for Laravel
PHP
45
star
9

api-manager

Api manager you won't hate. Beautify and unify your responses with the least effort possible.
PHP
38
star
10

ansible-composer

Install PHP Composer on Centos/Red Hat with Ansible
34
star
11

agency

A Neo4j (graph db based) content management system built with smart tools and compelling UI for the 21st century.
JavaScript
21
star
12

youtube

Fetch & sync videos and channels from Youtube API V3
PHP
16
star
13

iTunes

A simple yet full-fledged iTunes API client with caching support.
PHP
13
star
14

docker-nginx-php

A PHP application image with NGINX as a web server monitored by supervisord
Dockerfile
12
star
15

docker-php-mongo

PHP-FPM with MongoDB extension installed
10
star
16

social-auth

Social network authentication package
PHP
10
star
17

ansible-supervisor

An Ansible playbook role to install supervisord on CentOS/Red Hat/Fedora
10
star
18

mr-uploader

jQuery plugin for simplified photo cropping and uploading.
JavaScript
9
star
19

docker-hhvm

A docker image to run Laravel apps under Facebook's HHVM compiler in FastCGI mode behind an NGINX web server.
Shell
8
star
20

Android-wamp-client

Android client for WAMP v2 (Web Application Messaging Protocol) based on Jawampa library
Java
8
star
21

node-promise-cache

A promise-based cache store that preserves stored data types and is easily expandable with custom cache stores
CoffeeScript
8
star
22

ansible-redis

Install and configure Redis on Centos/Red Hat with Ansible
7
star
23

ansible-mongodb

Install MongoDB with Ansible on Centos/Red Hat
6
star
24

ansible-mysql

Install and configure MySQL on Centos/Red Hat with Ansible
5
star
25

docker-neo4j

An image to run a Neo4j container
Shell
5
star
26

ansible-haproxy

Install HAProxy on Centos/Red Hat with Ansible
4
star
27

assistant

Bunch of helper classes
PHP
4
star
28

docker-php-fpm

Run PHP FastCGI with common extensions out of the box
4
star
29

ansible-nginx-laravel

Ansible role for nginx with configuration for Laravel
4
star
30

ansible-docker

Install Docker on CentOS and Red Hat hosts. Used to enable the use of Ansible's Docker module.
4
star
31

tracing-go

Distributed tracing (OpenTracing) for Go made easy
Go
3
star
32

generator-tom

Yeoman Generator for AngularJS Apps in CoffeeScript
CoffeeScript
3
star
33

haproxy-config-manager

API built on Django Rest Framework to make scaling using HAProxy LB much easier.
Python
3
star
34

agency-deployment-provisioning

The server cluster provisioning of Agency for development and production using Ansible.
Shell
3
star
35

herald

Backend engineering code test.
PHP
2
star
36

country

PHP
2
star
37

docker-redis

A redis image suitable for production use
Shell
2
star
38

docker-base

A base image that allows simple ssh access through ssh keys
Shell
2
star
39

docker-laravel

Run Laravel projects using Docker and Nginx
2
star
40

ansible-deploy

Deploy Git repos to remote hosts using configurable SSH Keys
2
star
41

iTunes-distribution-metadata-generator

iTunes distribution metadata generator
PHP
2
star
42

go-init

An initial structure for building Go web apps.
Go
2
star
43

ansible-php-mongo

Install MongoClient class for PHP on Centos/Red Hat with Ansible
2
star
44

ecs-watchtower

ECS Watchtower is a health check script with a status page for AWS ECS tasks
JavaScript
1
star
45

php-coding-standards

PHP Coding Standards
1
star
46

yoda-prototype

PHP
1
star
47

flickr

PHP
1
star
48

oauth-clients-generator-redis

Redis Client Generator for the League's PHP OAuth 2.0 server
PHP
1
star
49

sample-laravel-testing-workflow

The code of the morning session on Friday 23-May-2014 in Cloud 5 introducing a better workflow with integration tests right from the kick off of the project
PHP
1
star
50

oclock

OClock is a Laravel schedules explorer
PHP
1
star
51

socialite-android

Light integration of social plugins on Android like login and sharing
Java
1
star
52

acid

Advanced content user-interface displayer
1
star
53

ansible-php-fpm

Install php-fpm with Ansible on Centos/Red Hat
1
star
54

nginx-basic-auth

NGINX with configurable basic auth using ENV vars
Shell
1
star