Commit f417f435 by Qiang Xue

Added `yii\composer\Installer::postCreateProject()` and modified the syntax of…

Added `yii\composer\Installer::postCreateProject()` and modified the syntax of calling installer methods in composer.json [skip ci]
parent 9f408af9
...@@ -25,21 +25,7 @@ ...@@ -25,21 +25,7 @@
"yiisoft/yii2-gii": "*", "yiisoft/yii2-gii": "*",
"yiisoft/yii2-faker": "*" "yiisoft/yii2-faker": "*"
}, },
"scripts": {
"post-create-project-cmd": [
"yii\\composer\\Installer::setPermission"
]
},
"config": { "config": {
"process-timeout": 1800 "process-timeout": 1800
},
"extra": {
"writable": [
"backend/runtime",
"backend/web/assets",
"frontend/runtime",
"frontend/web/assets"
]
} }
} }
...@@ -25,25 +25,26 @@ ...@@ -25,25 +25,26 @@
"yiisoft/yii2-gii": "*", "yiisoft/yii2-gii": "*",
"yiisoft/yii2-faker": "*" "yiisoft/yii2-faker": "*"
}, },
"config": {
"process-timeout": 1800
},
"scripts": { "scripts": {
"post-create-project-cmd": [ "post-create-project-cmd": [
"yii\\composer\\Installer::setPermission", "yii\\composer\\Installer::postCreateProject"
"yii\\composer\\Installer::generateCookieValidationKey"
] ]
}, },
"config": {
"process-timeout": 1800
},
"extra": { "extra": {
"writable": [ "yii\\composer\\Installer::postCreateProject": {
"runtime", "setPermission": [
"web/assets" {
], "runtime": "0777",
"executable": [ "web/assets": "0777",
"yii" "yii": "0755"
], }
"config": [ ],
"config/web.php" "generateCookieValidationKey": [
] "config/web.php"
]
}
} }
} }
...@@ -5,7 +5,7 @@ Yii Framework 2 composer extension Change Log ...@@ -5,7 +5,7 @@ Yii Framework 2 composer extension Change Log
-------------------------- --------------------------
- Bug #3438: Fixed support for non-lowercase package names (cebe) - 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 2.0.0-beta April 13, 2014
------------------------- -------------------------
......
...@@ -20,9 +20,6 @@ use Composer\Util\Filesystem; ...@@ -20,9 +20,6 @@ use Composer\Util\Filesystem;
class Installer extends LibraryInstaller class Installer extends LibraryInstaller
{ {
const EXTRA_BOOTSTRAP = 'bootstrap'; const EXTRA_BOOTSTRAP = 'bootstrap';
const EXTRA_WRITABLE = 'writable';
const EXTRA_EXECUTABLE = 'executable';
const EXTRA_CONFIG = 'config';
const EXTENSION_FILE = 'yiisoft/extensions.php'; const EXTENSION_FILE = 'yiisoft/extensions.php';
...@@ -223,53 +220,43 @@ EOF ...@@ -223,53 +220,43 @@ EOF
rmdir($yiiDir); rmdir($yiiDir);
} }
} }
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. * 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([ foreach ($paths as $path => $permission) {
self::EXTRA_WRITABLE => [], echo "chmod('$path', $permission)...";
self::EXTRA_EXECUTABLE => [],
], $event->getComposer()->getPackage()->getExtra());
foreach ((array) $options[self::EXTRA_WRITABLE] as $path) {
echo "Setting writable: $path ...";
if (is_dir($path) || is_file($path)) { if (is_dir($path) || is_file($path)) {
chmod($path, is_file($path) ? 0666 : 0777); chmod($path, octdec($permission));
echo "done\n"; echo "done.\n";
} else { } else {
echo "The directory or file was not found: " . getcwd() . DIRECTORY_SEPARATOR . $path; echo "file not found.\n";
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;
} }
} }
} }
/** /**
* Generates a cookie validation key for every app config listed in "config" in extra section. * 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(); $configs = func_get_args();
if (empty($extra[self::EXTRA_CONFIG])) {
return;
}
$key = self::generateRandomString(); $key = self::generateRandomString();
foreach ((array) $extra[self::EXTRA_CONFIG] as $config) { foreach ($configs as $config) {
if (is_file($config)) { if (is_file($config)) {
$content = preg_replace('/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/', "\\1'$key'", file_get_contents($config)); $content = preg_replace('/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/', "\\1'$key'", file_get_contents($config));
file_put_contents($config, $content); file_put_contents($config, $content);
...@@ -277,7 +264,7 @@ EOF ...@@ -277,7 +264,7 @@ EOF
} }
} }
public static function generateRandomString() protected static function generateRandomString()
{ {
if (!extension_loaded('mcrypt')) { if (!extension_loaded('mcrypt')) {
throw new \Exception('The mcrypt PHP extension is required by Yii2.'); throw new \Exception('The mcrypt PHP extension is required by Yii2.');
......
...@@ -184,7 +184,6 @@ Yii Framework 2 Change Log ...@@ -184,7 +184,6 @@ Yii Framework 2 Change Log
- Enh #4559: Added `beforeValidateAll` and `afterValidateAll` callbacks to `ActiveForm` (Alex-Code) - Enh #4559: Added `beforeValidateAll` and `afterValidateAll` callbacks to `ActiveForm` (Alex-Code)
- Enh #4566: Added client validation support for image validator (Skysplit, qiangxue) - Enh #4566: Added client validation support for image validator (Skysplit, qiangxue)
- Enh #4581: Added ability to disable url encoding in `UrlRule` (tadaszelvys) - 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 #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 #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) - Enh #4630: Added automatic generating of unique slug value to `yii\behaviors\Sluggable` (klimov-paul)
...@@ -254,6 +253,7 @@ Yii Framework 2 Change Log ...@@ -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: 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: 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: `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 #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 #4193: Added `yii\filters\Cors` CORS filter to allow Cross Origin Resource Sharing (pgaultier)
- New: Added `yii\base\InvalidValueException` (qiangxue) - New: Added `yii\base\InvalidValueException` (qiangxue)
......
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