From d047f71021eafaa4de7c6d596d4281a7d8fab0cc Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 22 Oct 2013 21:06:46 -0400 Subject: [PATCH] cleaned up Installer. --- extensions/composer/yii/composer/Installer.php | 41 ++------------------------ 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/extensions/composer/yii/composer/Installer.php b/extensions/composer/yii/composer/Installer.php index 8b7363c..0dda073 100644 --- a/extensions/composer/yii/composer/Installer.php +++ b/extensions/composer/yii/composer/Installer.php @@ -11,8 +11,6 @@ use Composer\Package\PackageInterface; use Composer\Installer\LibraryInstaller; use Composer\Repository\InstalledRepositoryInterface; use Composer\Script\CommandEvent; -use yii\console\Application; -use yii\console\Exception; /** * @author Qiang Xue @@ -20,11 +18,9 @@ use yii\console\Exception; */ class Installer extends LibraryInstaller { + const EXTRA_BOOTSTRAP = 'bootstrap'; const EXTRA_WRITABLE = 'writable'; const EXTRA_EXECUTABLE = 'executable'; - const EXTRA_CONFIG = 'yii-config'; - const EXTRA_COMMANDS = 'yii-commands'; - const EXTRA_BOOTSTRAP = 'bootstrap'; /** * @inheritdoc @@ -101,10 +97,10 @@ class Installer extends LibraryInstaller /** - * Sets the correct permissions of files and directories. + * Sets the correct permission for the files and directories listed in the extra section. * @param CommandEvent $event */ - public static function setPermissions($event) + public static function setPermission($event) { $options = array_merge([ self::EXTRA_WRITABLE => [], @@ -133,35 +129,4 @@ class Installer extends LibraryInstaller } } } - - /** - * Executes a yii command. - * @param CommandEvent $event - */ - public static function run($event) - { - $options = array_merge([ - self::EXTRA_COMMANDS => [], - ], $event->getComposer()->getPackage()->getExtra()); - - if (!isset($options[self::EXTRA_CONFIG])) { - throw new Exception('Please specify the "' . self::EXTRA_CONFIG . '" parameter in composer.json.'); - } - $configFile = getcwd() . '/' . $options[self::EXTRA_CONFIG]; - if (!is_file($configFile)) { - throw new Exception("Config file does not exist: $configFile"); - } - - require_once(__DIR__ . '/../../../yii2/yii/Yii.php'); - $application = new Application(require($configFile)); - $request = $application->getRequest(); - - foreach ((array)$options[self::EXTRA_COMMANDS] as $command) { - $params = str_getcsv($command, ' '); // see http://stackoverflow.com/a/6609509/291573 - $request->setParams($params); - list($route, $params) = $request->resolve(); - echo "Running command: yii {$command}\n"; - $application->runAction($route, $params); - } - } }