Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Illuminate\Console\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputOption;
- use Assetic\Asset\AssetCollection;
- use Assetic\Asset\FileAsset;
- use Minifier\MinFilter;
- class AssetsCompileCommand extends Command
- {
- /**
- * The console command name.
- *
- * @var string
- */
- protected $name = 'assets:compile';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Compiles resource files.';
- /**
- * Execute the console command.
- *
- * @return void
- */
- public function fire()
- {
- $minify = $this->option('minify');
- //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.
- if (App::environment() == 'production')
- {
- $minify = true;
- }
- $sections = Config::get('assets');
- foreach ($sections as $section => $assets)
- {
- foreach ($assets as $output => $input)
- {
- if (!is_string($output))
- {
- continue;
- }
- if (!is_array($input))
- {
- $input = array($input);
- }
- $filters = array();
- if ($minify)
- {
- if (ends_with($output, '.js'))
- {
- $filters[] = new MinFilter('js');
- }
- if (ends_with($output, '.css'))
- {
- $filters[] = new MinFilter('css');
- }
- }
- $collection = new AssetCollection(array(), $filters);
- foreach ($input as $asset)
- {
- $collection->add(new FileAsset(public_path().'/assets/'.$asset));
- }
- $this->info('Compiling '.$output);
- File::put(public_path().'/assets/'.$output, $collection->dump());
- }
- }
- }
- protected function getOptions()
- {
- return array(
- array('minify', 'm', InputOption::VALUE_NONE, 'Minify, defaults on in production.', null)
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement