Commit d047f710 by Qiang Xue

cleaned up Installer.

parent 0c517ce9
...@@ -11,8 +11,6 @@ use Composer\Package\PackageInterface; ...@@ -11,8 +11,6 @@ use Composer\Package\PackageInterface;
use Composer\Installer\LibraryInstaller; use Composer\Installer\LibraryInstaller;
use Composer\Repository\InstalledRepositoryInterface; use Composer\Repository\InstalledRepositoryInterface;
use Composer\Script\CommandEvent; use Composer\Script\CommandEvent;
use yii\console\Application;
use yii\console\Exception;
/** /**
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
...@@ -20,11 +18,9 @@ use yii\console\Exception; ...@@ -20,11 +18,9 @@ use yii\console\Exception;
*/ */
class Installer extends LibraryInstaller class Installer extends LibraryInstaller
{ {
const EXTRA_BOOTSTRAP = 'bootstrap';
const EXTRA_WRITABLE = 'writable'; const EXTRA_WRITABLE = 'writable';
const EXTRA_EXECUTABLE = 'executable'; const EXTRA_EXECUTABLE = 'executable';
const EXTRA_CONFIG = 'yii-config';
const EXTRA_COMMANDS = 'yii-commands';
const EXTRA_BOOTSTRAP = 'bootstrap';
/** /**
* @inheritdoc * @inheritdoc
...@@ -101,10 +97,10 @@ class Installer extends LibraryInstaller ...@@ -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 * @param CommandEvent $event
*/ */
public static function setPermissions($event) public static function setPermission($event)
{ {
$options = array_merge([ $options = array_merge([
self::EXTRA_WRITABLE => [], self::EXTRA_WRITABLE => [],
...@@ -133,35 +129,4 @@ class Installer extends LibraryInstaller ...@@ -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);
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment