Skip to content

Commit d902c82

Browse files
committed
Поиски DOCUMENT_ROOT в CLI
1 parent 77b066e commit d902c82

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

bin/db

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
1+
#!/usr/bin/env php
12
<?php
23

4+
use Symfony\Component\Console\Application;
35
use Prokl\DbCommands\Commands\DbDrop;
46
use Prokl\DbCommands\Commands\DbExport;
57
use Prokl\DbCommands\Commands\DbImport;
68
use Prokl\DbCommands\Configurator\ConsoleCommandConfiguratorSimple;
7-
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',
17+
18+
];
19+
$autoloadPath = '';
1320

14-
$autoloadPath = $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
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(),
@@ -24,4 +42,4 @@ $application = new ConsoleCommandConfiguratorSimple(
2442
);
2543

2644
$application->init();
27-
$application->run();
45+
$application->run();

bin/jedi

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
1+
#!/usr/bin/env php
12
<?php
23

34
use Prokl\JediLight\Application\Application;
45

56
@set_time_limit(0);
67

7-
$_SERVER['DOCUMENT_ROOT'] = __DIR__. DIRECTORY_SEPARATOR . '..';
8-
$GLOBALS['DOCUMENT_ROOT'] = $_SERVER['DOCUMENT_ROOT'];
8+
/** @var array $autoloadPaths Пути, где искать autoload.php композера. */
9+
$autoloadPaths = ['/../vendor/autoload.php',
10+
'/../../current/vendor/autoload.php',
11+
'/../../../vendor/autoload.php'
912

10-
$autoloadPath = $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
13+
];
14+
$autoloadPath = '';
15+
16+
foreach ($autoloadPaths as $path) {
17+
if (file_exists($autoloadPath = realpath(__DIR__) . $path)) {
18+
$autoloadPath = realpath(__DIR__) . $path;
19+
break;
20+
}
21+
}
22+
23+
if (!$autoloadPath) {
24+
die('Cannot find composer autoload.php file.' . PHP_EOL);
25+
}
1126

12-
/** @noinspection PhpIncludeInspection */
1327
require_once $autoloadPath;
1428

29+
// Считаю, что в данном случае DOCUMENT_ROOT находится на одном уровне с папкой vendor
30+
$_SERVER['DOCUMENT_ROOT'] = $GLOBALS['DOCUMENT_ROOT'] = dirname($autoloadPath) . '/..';
31+
1532
$jediApplication = new Application();
1633
$jediApplication->setDocumentRoot($_SERVER['DOCUMENT_ROOT']);
1734

18-
$jediApplication->run();
19-
35+
$jediApplication->run();

composer.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,10 @@
109109
"./bitrix/components/{$name}/": ["type:bitrix-d7-component", "type:bitrix-component"],
110110
"./bitrix/templates/{$name}/": ["type:bitrix-d7-template", "type:bitrix-theme"]
111111
}
112-
}
112+
},
113+
"bin": [
114+
"bin/module",
115+
"bin/console",
116+
"bin/db"
117+
]
113118
}

0 commit comments

Comments
 (0)