1
+ #!/usr/bin/env php
1
2
<?php
2
3
3
4
use Prokl \FrameworkExtensionBundle \Services \Bitrix \LoaderBitrix ;
4
5
use Prokl \CustomFrameworkExtensionsBundle \Services \Console \ConsoleCommandConfigurator ;
6
+ use Symfony \Component \Dotenv \Dotenv ;
5
7
6
8
@set_time_limit (0 );
7
9
8
- $_SERVER['DOCUMENT_ROOT'] = __DIR__. DIRECTORY_SEPARATOR . '..';
9
- $GLOBALS['DOCUMENT_ROOT'] = $_SERVER['DOCUMENT_ROOT'];
10
+ /** @var array $autoloadPaths Пути, где искать autoload.php композера. */
11
+ $ autoloadPaths = ['/../vendor/autoload.php ' , '/../../current/vendor/autoload.php ' ];
12
+ $ autoloadPath = '' ;
10
13
11
- $autoloadPath = $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
14
+ foreach ($ autoloadPaths as $ path ) {
15
+ if (file_exists ($ autoloadPath = realpath (__DIR__ ) . $ path )) {
16
+ $ autoloadPath = realpath (__DIR__ ) . $ path ;
17
+ break ;
18
+ }
19
+ }
20
+
21
+ if (!$ autoloadPath ) {
22
+ die ('Cannot find composer autoload.php file. ' . PHP_EOL );
23
+ }
12
24
13
- /** @noinspection PhpIncludeInspection */
14
25
require_once $ autoloadPath ;
15
26
27
+ $ dotenv = new Dotenv ();
28
+
29
+ $ envFile = realpath (__DIR__ .'/../ ' ) . '/.env ' ;
30
+
31
+ if (!file_exists ($ envFile )) {
32
+ die ('Cannot find .env file by path: ' . realpath (__DIR__ .'/../ ' . PHP_EOL ));
33
+ }
34
+ $ dotenv ->load ($ envFile );
35
+
36
+ // Попытка определить DOCUMENT_ROOT.
37
+ $ documentRoot = __DIR__ . '/.. ' ;
38
+ if (array_key_exists ('RELATIVE_DOCUMENT_ROOT_PATH ' , $ _ENV )) {
39
+ $ documentRoot = realpath (__DIR__ .'/.. ' ) . $ _ENV ['RELATIVE_DOCUMENT_ROOT_PATH ' ];
40
+ if (!file_exists ($ documentRoot )) {
41
+ die (
42
+ 'Path to root ' . $ _ENV ['RELATIVE_DOCUMENT_ROOT_PATH ' ] . ' from RELATIVE_DOCUMENT_ROOT_PATH variable not exists ' . PHP_EOL
43
+ );
44
+ }
45
+ }
46
+
47
+ $ _SERVER ['DOCUMENT_ROOT ' ] = $ documentRoot ;
48
+ $ GLOBALS ['DOCUMENT_ROOT ' ] = $ documentRoot ;
49
+
16
50
/**
17
51
* Загрузить Битрикс.
18
52
*/
@@ -21,7 +55,7 @@ $loaderBitrix->setDocumentRoot($_SERVER['DOCUMENT_ROOT']);
21
55
$ loaderBitrix ->initializeBitrix ();
22
56
23
57
if (!$ loaderBitrix ->isBitrixLoaded ()) {
24
- exit('Bitrix not initialized.');
58
+ exit ('Bitrix not initialized. ' . PHP_EOL );
25
59
}
26
60
27
61
if (!container ()->has ('console.command.manager ' )) {
0 commit comments