mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-16 06:17:56 +08:00
Merge branch 'master' of github.com:yiisoft/yii2
This commit is contained in:
@@ -27,11 +27,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"writable": [
|
"yii-install-writable": [
|
||||||
"runtime",
|
"runtime",
|
||||||
"www/assets"
|
"www/assets"
|
||||||
],
|
],
|
||||||
"executable": [
|
"yii-install-executable": [
|
||||||
"yii"
|
"yii"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
namespace yii\composer;
|
namespace yii\composer;
|
||||||
|
|
||||||
use Composer\Script\CommandEvent;
|
use Composer\Script\CommandEvent;
|
||||||
use yii\console;
|
use yii\console\Application;
|
||||||
|
use yii\console\Exception;
|
||||||
|
|
||||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||||
|
|
||||||
@@ -24,6 +25,11 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
|
|||||||
*/
|
*/
|
||||||
class InstallHandler
|
class InstallHandler
|
||||||
{
|
{
|
||||||
|
const PARAM_WRITABLE = 'yii-install-writable';
|
||||||
|
const PARAM_EXECUTABLE = 'yii-install-executable';
|
||||||
|
const PARAM_CONFIG = 'yii-install-config';
|
||||||
|
const PARAM_COMMANDS = 'yii-install-commands';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the correct permissions of files and directories.
|
* Sets the correct permissions of files and directories.
|
||||||
* @param CommandEvent $event
|
* @param CommandEvent $event
|
||||||
@@ -31,11 +37,11 @@ class InstallHandler
|
|||||||
public static function setPermissions($event)
|
public static function setPermissions($event)
|
||||||
{
|
{
|
||||||
$options = array_merge(array(
|
$options = array_merge(array(
|
||||||
'writable' => array(),
|
self::PARAM_WRITABLE => array(),
|
||||||
'executable' => array(),
|
self::PARAM_EXECUTABLE => array(),
|
||||||
), $event->getComposer()->getPackage()->getExtra());
|
), $event->getComposer()->getPackage()->getExtra());
|
||||||
|
|
||||||
foreach ((array)$options['writable'] as $path) {
|
foreach ((array)$options[self::PARAM_WRITABLE] as $path) {
|
||||||
echo "Setting writable: $path ...";
|
echo "Setting writable: $path ...";
|
||||||
if (is_dir($path)) {
|
if (is_dir($path)) {
|
||||||
chmod($path, 0777);
|
chmod($path, 0777);
|
||||||
@@ -46,7 +52,7 @@ class InstallHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ((array)$options['executable'] as $path) {
|
foreach ((array)$options[self::PARAM_EXECUTABLE] as $path) {
|
||||||
echo "Setting executable: $path ...";
|
echo "Setting executable: $path ...";
|
||||||
if (is_file($path)) {
|
if (is_file($path)) {
|
||||||
chmod($path, 0755);
|
chmod($path, 0755);
|
||||||
@@ -65,33 +71,28 @@ class InstallHandler
|
|||||||
public static function run($event)
|
public static function run($event)
|
||||||
{
|
{
|
||||||
$options = array_merge(array(
|
$options = array_merge(array(
|
||||||
'run' => array(),
|
self::PARAM_COMMANDS => array(),
|
||||||
'config' => null,
|
|
||||||
), $event->getComposer()->getPackage()->getExtra());
|
), $event->getComposer()->getPackage()->getExtra());
|
||||||
|
|
||||||
// resolve and include config file
|
if (!isset($options[self::PARAM_CONFIG])) {
|
||||||
if (($options['config'] === null)) {
|
throw new Exception('Please specify the "' . self::PARAM_CONFIG . '" parameter in composer.json.');
|
||||||
throw new console\Exception('Config file not specified in composer.json extra.config');
|
}
|
||||||
} else {
|
$configFile = getcwd() . '/' . $options[self::PARAM_CONFIG];
|
||||||
if (!is_file(getcwd() . '/' . $options['config'])) {
|
if (!is_file($configFile)) {
|
||||||
throw new console\Exception("Config file '{$options['config']}' specified in composer.json extra.config not found");
|
throw new Exception("Config file does not exist: $configFile");
|
||||||
} else {
|
|
||||||
$config = require($options['config']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare console application
|
|
||||||
require(__DIR__ . '/../../../yii2/yii/Yii.php');
|
require(__DIR__ . '/../../../yii2/yii/Yii.php');
|
||||||
$application = new \yii\console\Application($config);
|
$application = new Application(require($configFile));
|
||||||
$request = $application->getRequest();
|
$request = $application->getRequest();
|
||||||
|
|
||||||
// run commands from extra.run
|
foreach ((array)$options[self::PARAM_COMMANDS] as $command) {
|
||||||
foreach ((array)$options['run'] as $rawCommand) {
|
$params = str_getcsv($command, ' '); // see http://stackoverflow.com/a/6609509/291573
|
||||||
$opts = str_getcsv($rawCommand, ' '); // see http://stackoverflow.com/a/6609509/291573
|
array_shift($params);
|
||||||
$request->setParams($opts);
|
$request->setParams($params);
|
||||||
list($command, $params) = $request->resolve();
|
list($route, $params) = $request->resolve();
|
||||||
echo "Running command: yiic {$rawCommand}\n";
|
echo "Running command: yii {$command}\n";
|
||||||
$application->runAction($command, $params);
|
$application->runAction($route, $params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user