mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Added yii\composer\Installer::postCreateProject()
and modified the syntax of calling installer methods in composer.json [skip ci]
This commit is contained in:
@ -25,21 +25,7 @@
|
||||
"yiisoft/yii2-gii": "*",
|
||||
"yiisoft/yii2-faker": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"post-create-project-cmd": [
|
||||
"yii\\composer\\Installer::setPermission"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"process-timeout": 1800
|
||||
},
|
||||
"extra": {
|
||||
"writable": [
|
||||
"backend/runtime",
|
||||
"backend/web/assets",
|
||||
|
||||
"frontend/runtime",
|
||||
"frontend/web/assets"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -25,25 +25,26 @@
|
||||
"yiisoft/yii2-gii": "*",
|
||||
"yiisoft/yii2-faker": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"post-create-project-cmd": [
|
||||
"yii\\composer\\Installer::setPermission",
|
||||
"yii\\composer\\Installer::generateCookieValidationKey"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"process-timeout": 1800
|
||||
},
|
||||
"scripts": {
|
||||
"post-create-project-cmd": [
|
||||
"yii\\composer\\Installer::postCreateProject"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"writable": [
|
||||
"runtime",
|
||||
"web/assets"
|
||||
"yii\\composer\\Installer::postCreateProject": {
|
||||
"setPermission": [
|
||||
{
|
||||
"runtime": "0777",
|
||||
"web/assets": "0777",
|
||||
"yii": "0755"
|
||||
}
|
||||
],
|
||||
"executable": [
|
||||
"yii"
|
||||
],
|
||||
"config": [
|
||||
"generateCookieValidationKey": [
|
||||
"config/web.php"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ Yii Framework 2 composer extension Change Log
|
||||
--------------------------
|
||||
|
||||
- Bug #3438: Fixed support for non-lowercase package names (cebe)
|
||||
- Enh #4597: `yii\composer\Installer::setPermission()` supports setting permission for both directories and files now (qiangxue)
|
||||
- Chg: Added `yii\composer\Installer::postCreateProject()` and modified the syntax of calling installer methods in composer.json (qiangxue)
|
||||
|
||||
2.0.0-beta April 13, 2014
|
||||
-------------------------
|
||||
|
@ -20,9 +20,6 @@ use Composer\Util\Filesystem;
|
||||
class Installer extends LibraryInstaller
|
||||
{
|
||||
const EXTRA_BOOTSTRAP = 'bootstrap';
|
||||
const EXTRA_WRITABLE = 'writable';
|
||||
const EXTRA_EXECUTABLE = 'executable';
|
||||
const EXTRA_CONFIG = 'config';
|
||||
const EXTENSION_FILE = 'yiisoft/extensions.php';
|
||||
|
||||
|
||||
@ -224,52 +221,42 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
public static function postCreateProject($event)
|
||||
{
|
||||
$params = $event->getComposer()->getPackage()->getExtra();
|
||||
if (isset($params[__METHOD__]) && is_array($params[__METHOD__])) {
|
||||
foreach ($params[__METHOD__] as $method => $args) {
|
||||
call_user_func_array([__CLASS__, $method], (array) $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the correct permission for the files and directories listed in the extra section.
|
||||
* @param CommandEvent $event
|
||||
* @param array $paths the paths (keys) and the corresponding permission octal strings (values)
|
||||
*/
|
||||
public static function setPermission($event)
|
||||
public static function setPermission(array $paths)
|
||||
{
|
||||
$options = array_merge([
|
||||
self::EXTRA_WRITABLE => [],
|
||||
self::EXTRA_EXECUTABLE => [],
|
||||
], $event->getComposer()->getPackage()->getExtra());
|
||||
|
||||
foreach ((array) $options[self::EXTRA_WRITABLE] as $path) {
|
||||
echo "Setting writable: $path ...";
|
||||
foreach ($paths as $path => $permission) {
|
||||
echo "chmod('$path', $permission)...";
|
||||
if (is_dir($path) || is_file($path)) {
|
||||
chmod($path, is_file($path) ? 0666 : 0777);
|
||||
echo "done\n";
|
||||
chmod($path, octdec($permission));
|
||||
echo "done.\n";
|
||||
} else {
|
||||
echo "The directory or file was not found: " . getcwd() . DIRECTORY_SEPARATOR . $path;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ((array) $options[self::EXTRA_EXECUTABLE] as $path) {
|
||||
echo "Setting executable: $path ...";
|
||||
if (is_dir($path) || is_file($path)) {
|
||||
chmod($path, 0755);
|
||||
echo "done\n";
|
||||
} else {
|
||||
echo "\n\tThe directory or file was not found: " . getcwd() . DIRECTORY_SEPARATOR . $path . "\n";
|
||||
return;
|
||||
echo "file not found.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a cookie validation key for every app config listed in "config" in extra section.
|
||||
* @param CommandEvent $event
|
||||
* You can provide one or multiple parameters as the configuration files which need to have validation key inserted.
|
||||
*/
|
||||
public static function generateCookieValidationKey($event)
|
||||
public static function generateCookieValidationKey()
|
||||
{
|
||||
$extra = $event->getComposer()->getPackage()->getExtra();
|
||||
if (empty($extra[self::EXTRA_CONFIG])) {
|
||||
return;
|
||||
}
|
||||
$configs = func_get_args();
|
||||
$key = self::generateRandomString();
|
||||
foreach ((array) $extra[self::EXTRA_CONFIG] as $config) {
|
||||
foreach ($configs as $config) {
|
||||
if (is_file($config)) {
|
||||
$content = preg_replace('/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/', "\\1'$key'", file_get_contents($config));
|
||||
file_put_contents($config, $content);
|
||||
@ -277,7 +264,7 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
public static function generateRandomString()
|
||||
protected static function generateRandomString()
|
||||
{
|
||||
if (!extension_loaded('mcrypt')) {
|
||||
throw new \Exception('The mcrypt PHP extension is required by Yii2.');
|
||||
|
@ -184,7 +184,6 @@ Yii Framework 2 Change Log
|
||||
- Enh #4559: Added `beforeValidateAll` and `afterValidateAll` callbacks to `ActiveForm` (Alex-Code)
|
||||
- Enh #4566: Added client validation support for image validator (Skysplit, qiangxue)
|
||||
- Enh #4581: Added ability to disable url encoding in `UrlRule` (tadaszelvys)
|
||||
- Enh #4597: `yii\composer\Installer::setPermission()` supports setting permission for both directories and files now (qiangxue)
|
||||
- Enh #4602: Added $key param in ActionColumn buttons Closure call (disem)
|
||||
- Enh #4607: AR model will throw an exception if it does not have a primary key to avoid updating/deleting data massively (qiangxue)
|
||||
- Enh #4630: Added automatic generating of unique slug value to `yii\behaviors\Sluggable` (klimov-paul)
|
||||
@ -254,6 +253,7 @@ Yii Framework 2 Change Log
|
||||
- Chg: Added `prefix` column to `yii\log\DbTarget` to have the same amount of information logged as in files and emails (cebe)
|
||||
- Chg: Use `limit(null)` instead of `limit(-1)` in migration controller to be compatible to more backends (cebe)
|
||||
- Chg: `yii\web\Request::cookieValidationKey` must be explicitly specified for each application that wants to use cookie validation (qiangxue)
|
||||
- Chg: Added `yii\composer\Installer::postCreateProject()` and modified the syntax of calling installer methods in composer.json (qiangxue)
|
||||
- New #3911: Added `yii\behaviors\SluggableBehavior` that fills the specified model attribute with the transliterated and adjusted version to use in URLs (creocoder)
|
||||
- New #4193: Added `yii\filters\Cors` CORS filter to allow Cross Origin Resource Sharing (pgaultier)
|
||||
- New: Added `yii\base\InvalidValueException` (qiangxue)
|
||||
|
Reference in New Issue
Block a user