doctrine-dbal.php 1.28 KB
Newer Older
1 2
<?php

3
use Doctrine\DBAL\Tools\Console\ConsoleRunner;
4
use Symfony\Component\Console\Helper\HelperSet;
5

6
$files       = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'];
7 8
$loader      = null;
$cwd         = getcwd();
9
$directories = [$cwd, $cwd . DIRECTORY_SEPARATOR . 'config'];
10
$configFile  = null;
11

12 13 14
foreach ($files as $file) {
    if (file_exists($file)) {
        $loader = require $file;
15

16 17
        break;
    }
18
}
19

20
if (! $loader) {
21 22
    throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?');
}
23

24 25 26 27 28
foreach ($directories as $directory) {
    $configFile = $directory . DIRECTORY_SEPARATOR . 'cli-config.php';

    if (file_exists($configFile)) {
        break;
29
    }
30
}
31

32
if (! file_exists($configFile)) {
33
    ConsoleRunner::printCliConfigTemplate();
34

35 36 37
    exit(1);
}

38
if (! is_readable($configFile)) {
39
    echo 'Configuration file [' . $configFile . '] does not have read permission.' . PHP_EOL;
40

41 42 43
    exit(1);
}

44
$commands  = [];
45 46
$helperSet = require $configFile;

47
if (! $helperSet instanceof HelperSet) {
48
    foreach ($GLOBALS as $helperSetCandidate) {
49
        if ($helperSetCandidate instanceof HelperSet) {
50
            $helperSet = $helperSetCandidate;
51

52 53 54 55 56
            break;
        }
    }
}

Marco Pivetta's avatar
Marco Pivetta committed
57
ConsoleRunner::run($helperSet, $commands);