1
+ #!/usr/bin/env php
1
2
<?php
2
3
4
+ use Symfony \Component \Console \Application ;
3
5
use Prokl \DbCommands \Commands \DbDrop ;
4
6
use Prokl \DbCommands \Commands \DbExport ;
5
7
use Prokl \DbCommands \Commands \DbImport ;
6
8
use Prokl \DbCommands \Configurator \ConsoleCommandConfiguratorSimple ;
7
- use Symfony\Component\Console\Application;
8
9
9
10
@set_time_limit (0 );
10
11
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 = '' ;
13
20
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
+ }
15
31
16
- /** @noinspection PhpIncludeInspection */
17
32
require_once $ autoloadPath ;
18
33
34
+ // Считаю, что в данном случае DOCUMENT_ROOT находится на одном уровне с папкой vendor
35
+ $ _SERVER ['DOCUMENT_ROOT ' ] = $ GLOBALS ['DOCUMENT_ROOT ' ] = dirname ($ autoloadPath ) . '/.. ' ;
36
+
19
37
$ application = new ConsoleCommandConfiguratorSimple (
20
38
new Application (),
21
39
new DbImport (),
@@ -24,4 +42,4 @@ $application = new ConsoleCommandConfiguratorSimple(
24
42
);
25
43
26
44
$ application ->init ();
27
- $application->run();
45
+ $ application ->run ();
0 commit comments