patrickt

Basset Collections in a Provider for Laravel 4.1

Mar 27th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.42 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @filename: AssetCollectionProvider.php
  4.  * @path: app/providers/AssetCollectionProvider.php
  5.  */
  6. namespace Mysite\Providers;
  7.  
  8. use Illuminate\Support\ServiceProvider;
  9.  
  10. /**
  11.  * Asset Collection Builder
  12.  *
  13.  * The purpose of this is to build collections of assets (CSS, JS, maybe even images)
  14.  * that we will build, minify, and whatever else we need for use on the front-end.
  15.  *
  16.  * @author  Patrick Thurmond
  17.  * @version 1.0
  18.  *
  19.  */
  20. class AssetCollectionProvider extends ServiceProvider
  21. {
  22.     public function register() { } //Gotta declare this function or it cries a lot.
  23.  
  24.     public function boot()
  25.     {
  26.         /**
  27.          * Basset setup for the various sites.
  28.          *
  29.          * @Note: The problem we have here is how to work a different set for each site.
  30.          *      Reference: http://raffworks.com/laravel-4-assets-basset-less-part-1/
  31.          *
  32.          *      Solution: Using Basset we create a private directory to store all our
  33.          *          customizations for Bootstrap in.
  34.          *
  35.          *      We will do a collection for each company website.
  36.          *
  37.          *      Run the following in your builds:
  38.          *          php artisan basset:build bootstrap_siteA
  39.          *          php artisan basset:build bootstrap_siteB
  40.          *          php artisan basset:build bootstrap_siteC
  41.          *          php artisan basset:build bootstrap_siteD
  42.          *
  43.          * @Note2: We have to use \Basset instead of just Basset so that we can use the facades
  44.          *       and be able to statically call the functions like this.
  45.          */
  46.         // Define the Basset collection
  47.         \Basset::collection('bootstrap_siteA', function($collection)
  48.         {
  49.             // Collection definition.
  50.             $collection->add('../private/assets/siteA/less/bootstrap-custom.less');
  51.         })->apply('Less')->andApply('CssMin');
  52.  
  53.         \Basset::collection('bootstrap_siteB', function($collection)
  54.         {
  55.             // Collection definition.
  56.             $collection->add('../private/assets/siteB/less/bootstrap-custom.less');
  57.         })->apply('Less')->andApply('CssMin');
  58.  
  59.         \Basset::collection('bootstrap_siteC', function($collection)
  60.         {
  61.             // Collection definition.
  62.             $collection->add('../private/assets/siteC/less/bootstrap-custom.less');
  63.         })->apply('Less')->andApply('CssMin');
  64.  
  65.         \Basset::collection('bootstrap_siteD', function($collection)
  66.         {
  67.             // Collection definition.
  68.             $collection->add('../private/assets/siteD/less/bootstrap-custom.less');
  69.         })->apply('Less')->andApply('CssMin');
  70.     }
  71. }
  72. ?>
  73.  
  74. Then in app/config/app.php we need to add the provider to the providers array...
  75. <?php
  76.  
  77. return array(
  78.  
  79.     /*
  80.     |--------------------------------------------------------------------------
  81.     | Application Debug Mode
  82.     |--------------------------------------------------------------------------
  83.     |
  84.     | When your application is in debug mode, detailed error messages with
  85.     | stack traces will be shown on every error that occurs within your
  86.     | application. If disabled, a simple generic error page is shown.
  87.     |
  88.     */
  89.  
  90.     'debug' => true,
  91.     /*
  92.     |--------------------------------------------------------------------------
  93.     | Application URL
  94.     |--------------------------------------------------------------------------
  95.     |
  96.     | This URL is used by the console to properly generate URLs when using
  97.     | the Artisan command line tool. You should set this to the root of
  98.     | your application so that it is used when running Artisan tasks.
  99.     |
  100.     */
  101.  
  102.     'url' => 'http://localhost',
  103.     /*
  104.     |--------------------------------------------------------------------------
  105.     | Application Timezone
  106.     |--------------------------------------------------------------------------
  107.     |
  108.     | Here you may specify the default timezone for your application, which
  109.     | will be used by the PHP date and date-time functions. We have gone
  110.     | ahead and set this to a sensible default for you out of the box.
  111.     |
  112.     */
  113.  
  114.     'timezone' => 'America/Chicago',
  115.     /*
  116.     |--------------------------------------------------------------------------
  117.     | Application Locale Configuration
  118.     |--------------------------------------------------------------------------
  119.     |
  120.     | The application locale determines the default locale that will be used
  121.     | by the translation service provider. You are free to set this value
  122.     | to any of the locales which will be supported by the application.
  123.     |
  124.     */
  125.  
  126.     'locale' => 'en',
  127.     /*
  128.     |--------------------------------------------------------------------------
  129.     | Encryption Key
  130.     |--------------------------------------------------------------------------
  131.     |
  132.     | This key is used by the Illuminate encrypter service and should be set
  133.     | to a random, 32 character string, otherwise these encrypted strings
  134.     | will not be safe. Please do this before deploying an application!
  135.     |
  136.     */
  137.  
  138.     'key' => 'EoTsNdtG2I4K8QcK4YAXt0XET77ZMkt7',
  139.     /*
  140.     |--------------------------------------------------------------------------
  141.     | Autoloaded Service Providers
  142.     |--------------------------------------------------------------------------
  143.     |
  144.     | The service providers listed here will be automatically loaded on the
  145.     | request to your application. Feel free to add your own services to
  146.     | this array to grant expanded functionality to your applications.
  147.     |
  148.     */
  149.  
  150.     'providers' => array_merge(
  151.         array(
  152.             'Illuminate\Foundation\Providers\ArtisanServiceProvider',
  153.             'Illuminate\Auth\AuthServiceProvider',
  154.             'Illuminate\Cache\CacheServiceProvider',
  155.             'Illuminate\Session\CommandsServiceProvider',
  156.             'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
  157.             'Illuminate\Routing\ControllerServiceProvider',
  158.             'Illuminate\Cookie\CookieServiceProvider',
  159.             'Illuminate\Database\DatabaseServiceProvider',
  160.             'Illuminate\Encryption\EncryptionServiceProvider',
  161.             'Illuminate\Filesystem\FilesystemServiceProvider',
  162.             'Illuminate\Hashing\HashServiceProvider',
  163.             'Illuminate\Html\HtmlServiceProvider',
  164.             'Illuminate\Log\LogServiceProvider',
  165.             'Illuminate\Mail\MailServiceProvider',
  166.             'Illuminate\Database\MigrationServiceProvider',
  167.             'Illuminate\Pagination\PaginationServiceProvider',
  168.             'Illuminate\Queue\QueueServiceProvider',
  169.             'Illuminate\Redis\RedisServiceProvider',
  170.             'Illuminate\Remote\RemoteServiceProvider',
  171.             'Illuminate\Auth\Reminders\ReminderServiceProvider',
  172.             'Illuminate\Database\SeedServiceProvider',
  173.             'Illuminate\Session\SessionServiceProvider',
  174.             'Illuminate\Translation\TranslationServiceProvider',
  175.             'Illuminate\Validation\ValidationServiceProvider',
  176.             'Illuminate\View\ViewServiceProvider',
  177.             'Illuminate\Workbench\WorkbenchServiceProvider',
  178.             'Way\Generators\GeneratorsServiceProvider',
  179.             'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
  180.             'Laracasts\Utilities\UtilitiesServiceProvider',
  181.             'Basset\BassetServiceProvider',
  182.             'Mysite\Providers\AssetCollectionProvider'
  183.         )
  184.     ),
  185.     /*
  186.     |--------------------------------------------------------------------------
  187.     | Service Provider Manifest
  188.     |--------------------------------------------------------------------------
  189.     |
  190.     | The service provider manifest is used by Laravel to lazy load service
  191.     | providers which are not needed for each request, as well to keep a
  192.     | list of all of the services. Here, you may set its storage spot.
  193.     |
  194.     */
  195.  
  196.     'manifest' => storage_path() . '/meta',
  197.     /*
  198.     |--------------------------------------------------------------------------
  199.     | Class Aliases
  200.     |--------------------------------------------------------------------------
  201.     |
  202.     | This array of class aliases will be registered when this application
  203.     | is started. However, feel free to register as many as you wish as
  204.     | the aliases are "lazy" loaded so they don't hinder performance.
  205.     |
  206.     */
  207.  
  208.     'aliases' => array(
  209.  
  210.         'App' => 'Illuminate\Support\Facades\App',
  211.         'Artisan' => 'Illuminate\Support\Facades\Artisan',
  212.         'Auth' => 'Illuminate\Support\Facades\Auth',
  213.         'Blade' => 'Illuminate\Support\Facades\Blade',
  214.         'Cache' => 'Illuminate\Support\Facades\Cache',
  215.         'ClassLoader' => 'Illuminate\Support\ClassLoader',
  216.         'Config' => 'Illuminate\Support\Facades\Config',
  217.         'Controller' => 'Illuminate\Routing\Controller',
  218.         'Cookie' => 'Illuminate\Support\Facades\Cookie',
  219.         'Crypt' => 'Illuminate\Support\Facades\Crypt',
  220.         'DB' => 'Illuminate\Support\Facades\DB',
  221.         'Eloquent' => 'Illuminate\Database\Eloquent\Model',
  222.         'Event' => 'Illuminate\Support\Facades\Event',
  223.         'File' => 'Illuminate\Support\Facades\File',
  224.         'Form' => 'Illuminate\Support\Facades\Form',
  225.         'Hash' => 'Illuminate\Support\Facades\Hash',
  226.         'HTML' => 'Illuminate\Support\Facades\HTML',
  227.         'Input' => 'Illuminate\Support\Facades\Input',
  228.         'Lang' => 'Illuminate\Support\Facades\Lang',
  229.         'Log' => 'Illuminate\Support\Facades\Log',
  230.         'Mail' => 'Illuminate\Support\Facades\Mail',
  231.         'Paginator' => 'Illuminate\Support\Facades\Paginator',
  232.         'Password' => 'Illuminate\Support\Facades\Password',
  233.         'Queue' => 'Illuminate\Support\Facades\Queue',
  234.         'Redirect' => 'Illuminate\Support\Facades\Redirect',
  235.         'Redis' => 'Illuminate\Support\Facades\Redis',
  236.         'Request' => 'Illuminate\Support\Facades\Request',
  237.         'Response' => 'Illuminate\Support\Facades\Response',
  238.         'Route' => 'Illuminate\Support\Facades\Route',
  239.         'Schema' => 'Illuminate\Support\Facades\Schema',
  240.         'Seeder' => 'Illuminate\Database\Seeder',
  241.         'Session' => 'Illuminate\Support\Facades\Session',
  242.         'SSH' => 'Illuminate\Support\Facades\SSH',
  243.         'Str' => 'Illuminate\Support\Str',
  244.         'URL' => 'Illuminate\Support\Facades\URL',
  245.         'Validator' => 'Illuminate\Support\Facades\Validator',
  246.         'View' => 'Illuminate\Support\Facades\View',
  247.  
  248.         //External Tools
  249.         'Basset' => 'Basset\Facade'
  250.     ),
  251.  
  252. );
  253. ?>
Advertisement
Add Comment
Please, Sign In to add comment