Skip to content

Commit b4842ae

Browse files
committed
travis
1 parent 6ade6ff commit b4842ae

File tree

4 files changed

+60
-65
lines changed

4 files changed

+60
-65
lines changed

.travis.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@ install:
1919
- travis_retry composer global require "codeception/codeception=2.0.*" "codeception/specify=*" "codeception/verify=*"
2020
# setup application:
2121
- |
22-
ls -l
23-
chmod a+x ./init
24-
./init --env=Development
25-
sed -i s/root/travis/ ./common/config/main-local.php
26-
sed -i "s/'cookieValidationKey' => ''/'cookieValidationKey' => 'testkey'/" ./backend/config/main.php
27-
cd ./tests/codeception/backend && codecept build
28-
cd ./../common && codecept build
29-
cd ./../console && codecept build
30-
cd ./../rest && codecept build
31-
cd ./../../../
22+
php init --env=Development
23+
sed -i s/root/travis/ common/config/main-local.php
24+
sed -i "s/'cookieValidationKey' => ''/'cookieValidationKey' => 'testkey'/" backend/config/main.php
25+
cd tests/codeception/backend && codecept build
26+
cd ../common && codecept build
27+
cd ../console && codecept build
28+
cd ../rest && codecept build
29+
cd ../../../
3230
3331
before_script:
34-
- cd ./tests/codeception/bin && php yii migrate --interactive=0 && cd ../../..
32+
- cd tests/codeception/bin && php yii migrate --interactive=0 && cd ../../..
3533

3634
script:
3735
- |

codeception.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

init

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@
1313
* @copyright Copyright (c) 2008 Yii Software LLC
1414
* @license http://www.yiiframework.com/license/
1515
*/
16-
17-
if (!extension_loaded('mcrypt')) {
18-
die('The mcrypt PHP extension is required by Yii2.');
16+
if (!extension_loaded('openssl')) {
17+
die('The OpenSSL PHP extension is required by Yii2.');
1918
}
20-
2119
$params = getParams();
2220
$root = str_replace('\\', '/', __DIR__);
2321
$envs = require("$root/environments/index.php");
2422
$envNames = array_keys($envs);
25-
2623
echo "Yii Application Initialization Tool v1.0\n\n";
27-
2824
$envName = null;
2925
if (empty($params['env']) || $params['env'] === '1') {
3026
echo "Which environment do you want the application to be initialized in?\n\n";
@@ -33,27 +29,22 @@ if (empty($params['env']) || $params['env'] === '1') {
3329
}
3430
echo "\n Your choice [0-" . (count($envs) - 1) . ', or "q" to quit] ';
3531
$answer = trim(fgets(STDIN));
36-
3732
if (!ctype_digit($answer) || !in_array($answer, range(0, count($envs) - 1))) {
3833
echo "\n Quit initialization.\n";
3934
exit(0);
4035
}
41-
4236
if (isset($envNames[$answer])) {
4337
$envName = $envNames[$answer];
4438
}
4539
} else {
4640
$envName = $params['env'];
4741
}
48-
4942
if (!in_array($envName, $envNames)) {
5043
$envsList = implode(', ', $envNames);
5144
echo "\n $envName is not a valid environment. Try one of the following: $envsList. \n";
5245
exit(2);
5346
}
54-
5547
$env = $envs[$envName];
56-
5748
if (empty($params['env'])) {
5849
echo "\n Initialize the application under '{$envNames[$answer]}' environment? [yes|no] ";
5950
$answer = trim(fgets(STDIN));
@@ -62,25 +53,26 @@ if (empty($params['env'])) {
6253
exit(0);
6354
}
6455
}
65-
6656
echo "\n Start initialization ...\n\n";
6757
$files = getFileList("$root/environments/{$env['path']}");
58+
if (isset($env['skipFiles'])) {
59+
$skipFiles = $env['skipFiles'];
60+
array_walk($skipFiles, function(&$value) use($env, $root) { $value = "$root/$value"; });
61+
$files = array_diff($files, array_intersect_key($env['skipFiles'], array_filter($skipFiles, 'file_exists')));
62+
}
6863
$all = false;
6964
foreach ($files as $file) {
7065
if (!copyFile($root, "environments/{$env['path']}/$file", $file, $all, $params)) {
7166
break;
7267
}
7368
}
74-
75-
$callbacks = ['setCookieValidationKey', 'setWritable', 'setExecutable'];
69+
$callbacks = ['setCookieValidationKey', 'setWritable', 'setExecutable', 'createSymlink'];
7670
foreach ($callbacks as $callback) {
7771
if (!empty($env[$callback])) {
7872
$callback($root, $env[$callback]);
7973
}
8074
}
81-
8275
echo "\n ... initialization completed.\n\n";
83-
8476
function getFileList($root, $basePath = '')
8577
{
8678
$files = [];
@@ -100,7 +92,6 @@ function getFileList($root, $basePath = '')
10092
closedir($handle);
10193
return $files;
10294
}
103-
10495
function copyFile($root, $source, $target, &$all, $params)
10596
{
10697
if (!is_file($root . '/' . $source)) {
@@ -117,8 +108,6 @@ function copyFile($root, $source, $target, &$all, $params)
117108
} else {
118109
echo " exist $target\n";
119110
echo " ...overwrite? [Yes|No|All|Quit] ";
120-
121-
122111
$answer = !empty($params['overwrite']) ? $params['overwrite'] : trim(fgets(STDIN));
123112
if (!strncasecmp($answer, 'q', 1)) {
124113
return false;
@@ -144,15 +133,13 @@ function copyFile($root, $source, $target, &$all, $params)
144133
file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source));
145134
return true;
146135
}
147-
148136
function getParams()
149137
{
150138
$rawParams = [];
151139
if (isset($_SERVER['argv'])) {
152140
$rawParams = $_SERVER['argv'];
153141
array_shift($rawParams);
154142
}
155-
156143
$params = [];
157144
foreach ($rawParams as $param) {
158145
if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
@@ -164,32 +151,37 @@ function getParams()
164151
}
165152
return $params;
166153
}
167-
168154
function setWritable($root, $paths)
169155
{
170156
foreach ($paths as $writable) {
171157
echo " chmod 0777 $writable\n";
172158
@chmod("$root/$writable", 0777);
173159
}
174160
}
175-
176161
function setExecutable($root, $paths)
177162
{
178163
foreach ($paths as $executable) {
179164
echo " chmod 0755 $executable\n";
180165
@chmod("$root/$executable", 0755);
181166
}
182167
}
183-
184168
function setCookieValidationKey($root, $paths)
185169
{
186170
foreach ($paths as $file) {
187171
echo " generate cookie validation key in $file\n";
188172
$file = $root . '/' . $file;
189173
$length = 32;
190-
$bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
174+
$bytes = openssl_random_pseudo_bytes($length);
191175
$key = strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.');
192176
$content = preg_replace('/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/', "\\1'$key'", file_get_contents($file));
193177
file_put_contents($file, $content);
194178
}
195179
}
180+
function createSymlink($root, $links) {
181+
foreach ($links as $link => $target) {
182+
echo " symlink " . $root . "/" . $target . " " . $root . "/" . $link . "\n";
183+
//first removing folders to avoid errors if the folder already exists
184+
@rmdir($root . "/" . $link);
185+
@symlink($root . "/" . $target, $root . "/" . $link);
186+
}
187+
}

requirements.php

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,35 @@
99
* If you are using Linux you can create a hard link instead, using the following command:
1010
* ln requirements.php ../requirements.php
1111
*/
12-
1312
// you may need to adjust this path to the correct Yii framework path
1413
$frameworkPath = dirname(__FILE__) . '/vendor/yiisoft/yii2';
15-
1614
if (!is_dir($frameworkPath)) {
1715
echo '<h1>Error</h1>';
1816
echo '<p><strong>The path to yii framework seems to be incorrect.</strong></p>';
1917
echo '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) . '</abbr>.</p>';
2018
echo '<p>Please refer to the <abbr title="' . dirname(__FILE__) . '/README.md">README</abbr> on how to install Yii.</p>';
2119
}
22-
2320
require_once($frameworkPath . '/requirements/YiiRequirementChecker.php');
2421
$requirementsChecker = new YiiRequirementChecker();
25-
22+
$gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.';
23+
$gdOK = $imagickOK = false;
24+
if (extension_loaded('imagick')) {
25+
$imagick = new Imagick();
26+
$imagickFormats = $imagick->queryFormats('PNG');
27+
if (in_array('PNG', $imagickFormats)) {
28+
$imagickOK = true;
29+
} else {
30+
$imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.';
31+
}
32+
}
33+
if (extension_loaded('gd')) {
34+
$gdInfo = gd_info();
35+
if (!empty($gdInfo['FreeType Support'])) {
36+
$gdOK = true;
37+
} else {
38+
$gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.';
39+
}
40+
}
2641
/**
2742
* Adjust requirements according to your application specifics.
2843
*/
@@ -69,14 +84,22 @@
6984
'condition' => extension_loaded('apc'),
7085
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-apccache.html">ApcCache</a>',
7186
),
72-
// PHP ini :
73-
'phpSafeMode' => array(
74-
'name' => 'PHP safe mode',
87+
// CAPTCHA:
88+
array(
89+
'name' => 'GD PHP extension with FreeType support',
7590
'mandatory' => false,
76-
'condition' => $requirementsChecker->checkPhpIniOff("safe_mode"),
77-
'by' => 'File uploading and console command execution',
78-
'memo' => '"safe_mode" should be disabled at php.ini',
91+
'condition' => $gdOK,
92+
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
93+
'memo' => $gdMemo,
7994
),
95+
array(
96+
'name' => 'ImageMagick PHP extension with PNG support',
97+
'mandatory' => false,
98+
'condition' => $imagickOK,
99+
'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>',
100+
'memo' => $imagickMemo,
101+
),
102+
// PHP ini :
80103
'phpExposePhp' => array(
81104
'name' => 'Expose PHP',
82105
'mandatory' => false,
@@ -99,4 +122,4 @@
99122
'memo' => 'PHP mail SMTP server required',
100123
),
101124
);
102-
$requirementsChecker->checkYii()->check($requirements)->render();
125+
$requirementsChecker->checkYii()->check($requirements)->render();

0 commit comments

Comments
 (0)