Created
May 18, 2012 12:50
-
-
Save arjenjb/2725096 to your computer and use it in GitHub Desktop.
ScriptHandler to dump assetic assets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Symfony\Bundle\AsseticBundle\Composer; | |
use Symfony\Component\Process\PhpExecutableFinder; | |
use Symfony\Component\Process\Process; | |
class ScriptHandler | |
{ | |
public static function dumpAssets($event) | |
{ | |
$options = self::getOptions($event); | |
$appDir = $options['symfony-app-dir']; | |
$arguments = array(); | |
if ($options['assetic-dump-force']) | |
$arguments[] = '--force'; | |
if ($options['assetic-dump-asset-root'] !== null) | |
$arguments = escapeshellarg($options['assetic-dump-asset-root']); | |
static::executeCommand($event, $appDir, 'assetic:dump' . implode(' ', $arguments)); | |
} | |
protected static function executeCommand($event, $appDir, $cmd) | |
{ | |
$phpFinder = new PhpExecutableFinder; | |
$php = escapeshellarg($phpFinder->find()); | |
$console = escapeshellarg($appDir.'/console'); | |
if ($event->getIO()->isDecorated()) { | |
$console.= ' --ansi'; | |
} | |
$process = new Process($php.' '.$console.' '.$cmd); | |
$process->run(function ($type, $buffer) use($event) { $event->getIO()->write($buffer, false); }); | |
} | |
protected static function getOptions($event) | |
{ | |
$options = array_merge(array( | |
'assetic-dump-asset-root' => null, | |
'assetic-dump-force' => false, | |
), $event->getComposer()->getPackage()->getExtra()); | |
return $options; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment