mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Added install tool, moved all local configs and entry points to environments
This commit is contained in:
1
apps/advanced/.gitignore
vendored
Normal file
1
apps/advanced/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/yii
|
@ -20,12 +20,10 @@ DIRECTORY STRUCTURE
|
|||||||
```
|
```
|
||||||
common
|
common
|
||||||
config/ contains shared configurations
|
config/ contains shared configurations
|
||||||
env/ contains environment-based overrides
|
|
||||||
models/ contains model classes used in both backstage and frontend
|
models/ contains model classes used in both backstage and frontend
|
||||||
console
|
console
|
||||||
config/ contains console configurations
|
config/ contains console configurations
|
||||||
controllers/ contains console controllers (commands)
|
controllers/ contains console controllers (commands)
|
||||||
env/ contains environment-based overrides
|
|
||||||
migrations/ contains database migrations
|
migrations/ contains database migrations
|
||||||
models/ contains console-specific model classes
|
models/ contains console-specific model classes
|
||||||
runtime/ contains files generated during runtime
|
runtime/ contains files generated during runtime
|
||||||
@ -33,7 +31,6 @@ backstage
|
|||||||
assets/ contains application assets such as JavaScript and CSS
|
assets/ contains application assets such as JavaScript and CSS
|
||||||
config/ contains backstage configurations
|
config/ contains backstage configurations
|
||||||
controllers/ contains Web controller classes
|
controllers/ contains Web controller classes
|
||||||
env/ contains environment-based overrides
|
|
||||||
models/ contains backstage-specific model classes
|
models/ contains backstage-specific model classes
|
||||||
runtime/ contains files generated during runtime
|
runtime/ contains files generated during runtime
|
||||||
views/ contains view files for the Web application
|
views/ contains view files for the Web application
|
||||||
@ -42,12 +39,12 @@ frontend
|
|||||||
assets/ contains application assets such as JavaScript and CSS
|
assets/ contains application assets such as JavaScript and CSS
|
||||||
config/ contains frontend configurations
|
config/ contains frontend configurations
|
||||||
controllers/ contains Web controller classes
|
controllers/ contains Web controller classes
|
||||||
env/ contains environment-based overrides
|
|
||||||
models/ contains frontend-specific model classes
|
models/ contains frontend-specific model classes
|
||||||
runtime/ contains files generated during runtime
|
runtime/ contains files generated during runtime
|
||||||
views/ contains view files for the Web application
|
views/ contains view files for the Web application
|
||||||
www/ contains the entry script and Web resources
|
www/ contains the entry script and Web resources
|
||||||
vendor/ contains dependent 3rd-party packages
|
vendor/ contains dependent 3rd-party packages
|
||||||
|
environments/ contains environment-based overrides
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
0
apps/advanced/console/controllers/.gitkeep
Normal file
0
apps/advanced/console/controllers/.gitkeep
Normal file
@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @link http://www.yiiframework.com/
|
|
||||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
|
||||||
* @license http://www.yiiframework.com/license/
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace app\controllers;
|
|
||||||
use yii\console\Controller;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This command echos what the first argument that you have entered.
|
|
||||||
*
|
|
||||||
* This command is provided as an example for you to learn how to create console commands.
|
|
||||||
*
|
|
||||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
|
||||||
class HelloController extends Controller
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* This command echos what you have entered as the message.
|
|
||||||
* @param string $message the message to be echoed.
|
|
||||||
*/
|
|
||||||
public function actionIndex($message = 'hello world')
|
|
||||||
{
|
|
||||||
echo $message."\n";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
use yii\console\Controller;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* InstallController
|
|
||||||
*/
|
|
||||||
class InstallController extends Controller
|
|
||||||
{
|
|
||||||
public function actionIndex()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
1
apps/advanced/console/models/.gitkeep
Normal file
1
apps/advanced/console/models/.gitkeep
Normal file
@ -0,0 +1 @@
|
|||||||
|
*
|
@ -16,11 +16,10 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
|
|||||||
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
|
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
|
||||||
require(__DIR__ . '/vendor/autoload.php');
|
require(__DIR__ . '/vendor/autoload.php');
|
||||||
|
|
||||||
$config = require(__DIR__ . '/console/config/main.php');
|
$config = yii\helpers\ArrayHelper::merge(
|
||||||
$localConfig = __DIR__ . '/console/config/main-local.php';
|
require(__DIR__ . '/console/config/main.php'),
|
||||||
if (is_file($localeConfig)) {
|
require(__DIR__ . '/console/config/main-local.php')
|
||||||
$config = yii\helpers\ArrayHelper::merge($config, require($localConfig));
|
);
|
||||||
}
|
|
||||||
|
|
||||||
$application = new yii\console\Application($config);
|
$application = new yii\console\Application($config);
|
||||||
$application->run();
|
$application->run();
|
38
apps/advanced/environments/index.php
Normal file
38
apps/advanced/environments/index.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The manifest of files that are local to specific environment.
|
||||||
|
* This file returns a list of environments that the application
|
||||||
|
* may be installed under. The returned data must be in the following
|
||||||
|
* format:
|
||||||
|
*
|
||||||
|
* ```php
|
||||||
|
* return array(
|
||||||
|
* 'environment name' => array(
|
||||||
|
* 'path' => 'directory storing the local files',
|
||||||
|
* 'writable' => array(
|
||||||
|
* // list of directories that should be set writable
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* );
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
return array(
|
||||||
|
'Development' => array(
|
||||||
|
'path' => 'dev',
|
||||||
|
'writable' => array(
|
||||||
|
// handled by composer.json already
|
||||||
|
),
|
||||||
|
'executable' => array(
|
||||||
|
'yiic',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'Production' => array(
|
||||||
|
'path' => 'prod',
|
||||||
|
'writable' => array(
|
||||||
|
// handled by composer.json already
|
||||||
|
),
|
||||||
|
'executable' => array(
|
||||||
|
'yiic',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
111
apps/advanced/install
Normal file
111
apps/advanced/install
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
$root = str_replace('\\', '/', __DIR__);
|
||||||
|
$envs = require("$root/install/index.php");
|
||||||
|
$envNames = array_keys($envs);
|
||||||
|
|
||||||
|
echo "Yii Application Installation Tool v1.0\n\n";
|
||||||
|
echo "Which environment do you want to install the application to?\n\n";
|
||||||
|
foreach ($envNames as $i => $name) {
|
||||||
|
echo " [$i] $name\n";
|
||||||
|
}
|
||||||
|
echo "\n Your choice [0-" . (count($envs) - 1) . ', or "q" to quit] ';
|
||||||
|
$answer = trim(fgets(STDIN));
|
||||||
|
if (!ctype_digit($answer) || !isset($envNames[$answer])) {
|
||||||
|
echo "\n Quit installation.\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$env = $envs[$envNames[$answer]];
|
||||||
|
echo "\n Install the application under '{$envNames[$answer]}' environment? [yes|no] ";
|
||||||
|
$answer = trim(fgets(STDIN));
|
||||||
|
if (strncasecmp($answer, 'y', 1)) {
|
||||||
|
echo "\n Quit installation.\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "\n Start installation ...\n\n";
|
||||||
|
$files = getFileList("$root/install/{$env['path']}");
|
||||||
|
$all = false;
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if (!copyFile($root, "install/{$env['path']}/$file", $file, $all)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($env['writable'])) {
|
||||||
|
foreach ($env['writable'] as $writable) {
|
||||||
|
echo " chmod 0777 $writable\n";
|
||||||
|
@chmod("$root/$writable", 0777);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($env['executable'])) {
|
||||||
|
foreach ($env['executable'] as $executable) {
|
||||||
|
echo " chmod 0755 $executable\n";
|
||||||
|
@chmod("$root/$executable", 0755);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "\n ... installation completed.\n\n";
|
||||||
|
|
||||||
|
function getFileList($root, $basePath = '')
|
||||||
|
{
|
||||||
|
$files = array();
|
||||||
|
$handle = opendir($root);
|
||||||
|
while (($path = readdir($handle)) !== false) {
|
||||||
|
if ($path === '.svn' || $path === '.' || $path === '..') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$fullPath = "$root/$path";
|
||||||
|
$relativePath = $basePath === '' ? $path : "$basePath/$path";
|
||||||
|
if (is_dir($fullPath)) {
|
||||||
|
$files = array_merge($files, getFileList($fullPath, $relativePath));
|
||||||
|
} else {
|
||||||
|
$files[] = $relativePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($handle);
|
||||||
|
return $files;
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyFile($root, $source, $target, &$all)
|
||||||
|
{
|
||||||
|
if (!is_file($root . '/' . $source)) {
|
||||||
|
echo " skip $target ($source not exist)\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (is_file($root . '/' . $target)) {
|
||||||
|
if (file_get_contents($root . '/' . $source) === file_get_contents($root . '/' . $target)) {
|
||||||
|
echo " unchanged $target\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ($all) {
|
||||||
|
echo " overwrite $target\n";
|
||||||
|
} else {
|
||||||
|
echo " exist $target\n";
|
||||||
|
echo " ...overwrite? [Yes|No|All|Quit] ";
|
||||||
|
$answer = trim(fgets(STDIN));
|
||||||
|
if (!strncasecmp($answer, 'q', 1)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (!strncasecmp($answer, 'y', 1)) {
|
||||||
|
echo " overwrite $target\n";
|
||||||
|
} else {
|
||||||
|
if (!strncasecmp($answer, 'a', 1)) {
|
||||||
|
echo " overwrite $target\n";
|
||||||
|
$all = true;
|
||||||
|
} else {
|
||||||
|
echo " skip $target\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
echo " generate $target\n";
|
||||||
|
@mkdir(dirname($root . '/' . $target), 0777, true);
|
||||||
|
file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source));
|
||||||
|
return true;
|
||||||
|
}
|
Reference in New Issue
Block a user