From 31d9cbd9a1abe0ca679ba603150404b63f4d376b Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Wed, 22 May 2013 23:41:50 +0200 Subject: [PATCH] added run method to execute yii commands --- .../composer/yii/composer/InstallHandler.php | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/extensions/composer/yii/composer/InstallHandler.php b/extensions/composer/yii/composer/InstallHandler.php index 6d43abd..794ec24 100644 --- a/extensions/composer/yii/composer/InstallHandler.php +++ b/extensions/composer/yii/composer/InstallHandler.php @@ -9,10 +9,16 @@ namespace yii\composer; use Composer\Script\CommandEvent; +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 + * @author Tobias Munk * @since 2.0 */ class InstallHandler @@ -50,4 +56,31 @@ class InstallHandler } } } + + /** + * Executes a yii command. + * @param CommandEvent $event + */ + public static function run($event) + { + $options = array_merge(array( + 'run' => array(), + ), $event->getComposer()->getPackage()->getExtra()); + + $appPath = realpath(__DIR__ . '/../../../../..'); + + require($appPath . '/vendor/yiisoft/yii2/yii/Yii.php'); + require($appPath . '/vendor/autoload.php'); + $config = require($appPath . '/config/console.php'); + + foreach((array)$options['run'] as $params){ + $command = $params[0]; + unset($params[0]); + $params = array(); + // TODO: add params to array + echo "Running command: {$command}\n"; + $application = new \yii\console\Application($config); + $application->runAction($command, $params); + } + } }