Advertisement
Guest User

Untitled

a guest
Sep 20th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. <?php
  2. use Illuminate\Console\Command;
  3. use Symfony\Component\Console\Input\InputArgument;
  4. use Symfony\Component\Console\Input\InputOption;
  5. use Assetic\Asset\AssetCollection;
  6. use Assetic\Asset\FileAsset;
  7. use Minifier\MinFilter;
  8.  
  9. class AssetsCompileCommand extends Command
  10. {
  11.  
  12.     /**
  13.      * The console command name.
  14.      *
  15.      * @var string
  16.      */
  17.     protected $name = 'assets:compile';
  18.  
  19.     /**
  20.      * The console command description.
  21.      *
  22.      * @var string
  23.      */
  24.     protected $description = 'Compiles resource files.';
  25.  
  26.     /**
  27.      * Execute the console command.
  28.      *
  29.      * @return void
  30.      */
  31.     public function fire()
  32.     {
  33.         $minify = $this->option('minify');
  34.         //normally you should never target a specific environment, however it's entirely possible to access this same code branch by specifying minify on your vm or dev.
  35.         if (App::environment() == 'production')
  36.         {
  37.             $minify = true;
  38.         }
  39.         $sections = Config::get('assets');
  40.         foreach ($sections as $section => $assets)
  41.         {
  42.             foreach ($assets as $output => $input)
  43.             {
  44.                 if (!is_string($output))
  45.                 {
  46.                     continue;
  47.                 }
  48.  
  49.                 if (!is_array($input))
  50.                 {
  51.                     $input = array($input);
  52.                 }
  53.  
  54.                 $filters = array();
  55.                 if ($minify)
  56.                 {
  57.                     if (ends_with($output, '.js'))
  58.                     {
  59.                         $filters[] = new MinFilter('js');
  60.                     }
  61.                     if (ends_with($output, '.css'))
  62.                     {
  63.                         $filters[] = new MinFilter('css');
  64.                     }
  65.                 }
  66.  
  67.                 $collection = new AssetCollection(array(), $filters);
  68.                 foreach ($input as $asset)
  69.                 {
  70.                     $collection->add(new FileAsset(public_path().'/assets/'.$asset));
  71.                 }
  72.                 $this->info('Compiling '.$output);
  73.                 File::put(public_path().'/assets/'.$output, $collection->dump());
  74.             }
  75.         }
  76.     }
  77.  
  78.     protected function getOptions()
  79.     {
  80.         return array(
  81.             array('minify', 'm', InputOption::VALUE_NONE, 'Minify, defaults on in production.', null)
  82.         );
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement