Skip to content

Commit

Permalink
Поиски DOCUMENT_ROOT в CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Aug 16, 2021
1 parent 77b066e commit d902c82
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
30 changes: 24 additions & 6 deletions bin/db
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
#!/usr/bin/env php
<?php

use Symfony\Component\Console\Application;
use Prokl\DbCommands\Commands\DbDrop;
use Prokl\DbCommands\Commands\DbExport;
use Prokl\DbCommands\Commands\DbImport;
use Prokl\DbCommands\Configurator\ConsoleCommandConfiguratorSimple;
use Symfony\Component\Console\Application;

@set_time_limit(0);

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

];
$autoloadPath = '';

$autoloadPath = $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
foreach ($autoloadPaths as $path) {
if (file_exists($autoloadPath = realpath(__DIR__) . $path)) {
$autoloadPath = realpath(__DIR__) . $path;
break;
}
}

if (!$autoloadPath) {
die('Cannot find composer autoload.php file.' . PHP_EOL);
}

/** @noinspection PhpIncludeInspection */
require_once $autoloadPath;

// Считаю, что в данном случае DOCUMENT_ROOT находится на одном уровне с папкой vendor
$_SERVER['DOCUMENT_ROOT'] = $GLOBALS['DOCUMENT_ROOT'] = dirname($autoloadPath) . '/..';

$application = new ConsoleCommandConfiguratorSimple(
new Application(),
new DbImport(),
Expand All @@ -24,4 +42,4 @@ $application = new ConsoleCommandConfiguratorSimple(
);

$application->init();
$application->run();
$application->run();
28 changes: 22 additions & 6 deletions bin/jedi
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
#!/usr/bin/env php
<?php

use Prokl\JediLight\Application\Application;

@set_time_limit(0);

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

$autoloadPath = $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
];
$autoloadPath = '';

foreach ($autoloadPaths as $path) {
if (file_exists($autoloadPath = realpath(__DIR__) . $path)) {
$autoloadPath = realpath(__DIR__) . $path;
break;
}
}

if (!$autoloadPath) {
die('Cannot find composer autoload.php file.' . PHP_EOL);
}

/** @noinspection PhpIncludeInspection */
require_once $autoloadPath;

// Считаю, что в данном случае DOCUMENT_ROOT находится на одном уровне с папкой vendor
$_SERVER['DOCUMENT_ROOT'] = $GLOBALS['DOCUMENT_ROOT'] = dirname($autoloadPath) . '/..';

$jediApplication = new Application();
$jediApplication->setDocumentRoot($_SERVER['DOCUMENT_ROOT']);

$jediApplication->run();

$jediApplication->run();
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,10 @@
"./bitrix/components/{$name}/": ["type:bitrix-d7-component", "type:bitrix-component"],
"./bitrix/templates/{$name}/": ["type:bitrix-d7-template", "type:bitrix-theme"]
}
}
},
"bin": [
"bin/module",
"bin/console",
"bin/db"
]
}

0 comments on commit d902c82

Please sign in to comment.