Skip to content

Commit 53d896e

Browse files
authored
Merge pull request #146 from yiisoft/requirements-searchpath
search for framework path in requirements.php
2 parents 0c87fab + 1c40724 commit 53d896e

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

requirements.php

+29-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,36 @@
1111
*/
1212

1313
// you may need to adjust this path to the correct Yii framework path
14-
$frameworkPath = dirname(__FILE__) . '/vendor/yiisoft/yii2';
14+
// uncomment and adjust the following line if Yii is not located at the default path
15+
//$frameworkPath = dirname(__FILE__) . '/vendor/yiisoft/yii2';
1516

16-
if (!is_dir($frameworkPath)) {
17-
echo '<h1>Error</h1>';
18-
echo '<p><strong>The path to yii framework seems to be incorrect.</strong></p>';
19-
echo '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) . '</abbr>.</p>';
20-
echo '<p>Please refer to the <abbr title="' . dirname(__FILE__) . '/README.md">README</abbr> on how to install Yii.</p>';
17+
18+
if (!isset($frameworkPath)) {
19+
$searchPaths = [
20+
dirname(__FILE__) . '/vendor/yiisoft/yii2',
21+
dirname(__FILE__) . '/../vendor/yiisoft/yii2',
22+
];
23+
foreach($searchPaths as $path) {
24+
if (is_dir($path)) {
25+
$frameworkPath = $path;
26+
break;
27+
}
28+
}
29+
}
30+
31+
if (!isset($frameworkPath) || !is_dir($frameworkPath)) {
32+
$message = "<h1>Error</h1>\n\n"
33+
. "<p><strong>The path to yii framework seems to be incorrect.</strong></p>\n"
34+
. '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) . "</abbr>.</p>\n"
35+
. '<p>Please refer to the <abbr title="' . dirname(__FILE__) . "/README.md\">README</abbr> on how to install Yii.</p>\n";
36+
37+
if (!empty($_SERVER['argv'])) {
38+
// do not print HTML when used in console mode
39+
echo strip_tags($message);
40+
} else {
41+
echo $message;
42+
}
43+
exit(1);
2144
}
2245

2346
require_once($frameworkPath . '/requirements/YiiRequirementChecker.php');

0 commit comments

Comments
 (0)