Skip to content

Commit ae917cd

Browse files
committed
Поиски DOCUMENT_ROOT
1 parent e4e57c0 commit ae917cd

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2020-2021 Fedor Gavrilov
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

bin/db

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env php
12
<?php
23

34
use Prokl\DbCommands\Commands\DbDrop;
@@ -8,14 +9,31 @@ use Symfony\Component\Console\Application;
89

910
@set_time_limit(0);
1011

11-
$_SERVER['DOCUMENT_ROOT'] = __DIR__. DIRECTORY_SEPARATOR . '..';
12-
$GLOBALS['DOCUMENT_ROOT'] = $_SERVER['DOCUMENT_ROOT'];
12+
/** @var array $autoloadPaths Пути, где искать autoload.php композера. */
13+
$autoloadPaths = ['/../vendor/autoload.php',
14+
'/../../current/vendor/autoload.php',
15+
'/../../../vendor/autoload.php',
16+
'/../../../../vendor/autoload.php',
1317

14-
$autoloadPath = $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
18+
];
19+
$autoloadPath = '';
20+
21+
foreach ($autoloadPaths as $path) {
22+
if (file_exists($autoloadPath = realpath(__DIR__) . $path)) {
23+
$autoloadPath = realpath(__DIR__) . $path;
24+
break;
25+
}
26+
}
27+
28+
if (!$autoloadPath) {
29+
die('Cannot find composer autoload.php file.' . PHP_EOL);
30+
}
1531

16-
/** @noinspection PhpIncludeInspection */
1732
require_once $autoloadPath;
1833

34+
// Считаю, что в данном случае DOCUMENT_ROOT находится на одну папку выше, чем папка vendor
35+
$_SERVER['DOCUMENT_ROOT'] = $GLOBALS['DOCUMENT_ROOT'] = dirname($autoloadPath) . '/..';
36+
1937
$application = new ConsoleCommandConfiguratorSimple(
2038
new Application(),
2139
new DbImport(),

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
"Prokl\\DbCommands\\": "src"
2525
}
2626
},
27+
"bin": [
28+
"bin/db"
29+
],
2730
"require": {
28-
"php": ">=7.3",
31+
"php": ">=7.3 || ^8.0",
2932
"ifsnop/mysqldump-php": "^2.9",
30-
"symfony/console": "~4 | ~5",
31-
"symfony/dotenv": "~4 | ~5"
33+
"symfony/console": "^4.4 | ^5.0",
34+
"symfony/dotenv": "^4.4 | ^5.0"
3235
}
3336
}

readme.MD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@
2323
`<название базы>.sql`
2424
3) `php bin/db db:import <путь к файлу c дампом> backup=false` - импорт базы. Если выставить `backup` в `true`, то команда
2525
на всякий случай сделает резервную копию текущей базы и "в случае чего" с импортом новой базы восстановит ее.
26+
27+
Или вместо `php bin` можно использовать `./vendor/bin`

0 commit comments

Comments
 (0)