|
|
|
@ -8,11 +8,18 @@
|
|
|
|
|
namespace yii\composer; |
|
|
|
|
|
|
|
|
|
use Composer\Script\CommandEvent; |
|
|
|
|
use yii\console; |
|
|
|
|
|
|
|
|
|
defined('YII_DEBUG') or define('YII_DEBUG', true); |
|
|
|
|
|
|
|
|
|
// fcgi doesn't have STDIN defined by default |
|
|
|
|
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* InstallHandler is called by Composer after it installs/updates the current package. |
|
|
|
|
* |
|
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
|
* @author Tobias Munk <schmunk@usrbin.de> |
|
|
|
|
* @since 2.0 |
|
|
|
|
*/ |
|
|
|
|
class InstallHandler |
|
|
|
@ -50,4 +57,41 @@ class InstallHandler
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Executes a yii command. |
|
|
|
|
* @param CommandEvent $event |
|
|
|
|
*/ |
|
|
|
|
public static function run($event) |
|
|
|
|
{ |
|
|
|
|
$options = array_merge(array( |
|
|
|
|
'run' => array(), |
|
|
|
|
'config' => null, |
|
|
|
|
), $event->getComposer()->getPackage()->getExtra()); |
|
|
|
|
|
|
|
|
|
// resolve and include config file |
|
|
|
|
if (($options['config'] === null)) { |
|
|
|
|
throw new console\Exception('Config file not specified in composer.json extra.config'); |
|
|
|
|
} else { |
|
|
|
|
if (!is_file(getcwd() . '/' . $options['config'])) { |
|
|
|
|
throw new console\Exception("Config file '{$options['config']}' specified in composer.json extra.config not found"); |
|
|
|
|
} else { |
|
|
|
|
$config = require($options['config']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// prepare console application |
|
|
|
|
require(__DIR__ . '/../../../yii2/yii/Yii.php'); |
|
|
|
|
$application = new \yii\console\Application($config); |
|
|
|
|
$request = $application->getRequest(); |
|
|
|
|
|
|
|
|
|
// run commands from extra.run |
|
|
|
|
foreach ((array)$options['run'] as $rawCommand) { |
|
|
|
|
$opts = str_getcsv($rawCommand, ' '); // see http://stackoverflow.com/a/6609509/291573 |
|
|
|
|
$request->setParams($opts); |
|
|
|
|
list($command, $params) = $request->resolve(); |
|
|
|
|
echo "Running command: yiic {$rawCommand}\n"; |
|
|
|
|
$application->runAction($command, $params); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|