doctrine-dbal.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. use Doctrine\DBAL\Tools\Console\ConsoleRunner;
  3. use Symfony\Component\Console\Helper\HelperSet;
  4. $files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'];
  5. $loader = null;
  6. $cwd = getcwd();
  7. $directories = [$cwd, $cwd . DIRECTORY_SEPARATOR . 'config'];
  8. $configFile = null;
  9. foreach ($files as $file) {
  10. if (file_exists($file)) {
  11. $loader = require $file;
  12. break;
  13. }
  14. }
  15. if (! $loader) {
  16. throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?');
  17. }
  18. foreach ($directories as $directory) {
  19. $configFile = $directory . DIRECTORY_SEPARATOR . 'cli-config.php';
  20. if (file_exists($configFile)) {
  21. break;
  22. }
  23. }
  24. if (! file_exists($configFile)) {
  25. ConsoleRunner::printCliConfigTemplate();
  26. exit(1);
  27. }
  28. if (! is_readable($configFile)) {
  29. echo 'Configuration file [' . $configFile . '] does not have read permission.' . PHP_EOL;
  30. exit(1);
  31. }
  32. $commands = [];
  33. $helperSet = require $configFile;
  34. if (! $helperSet instanceof HelperSet) {
  35. foreach ($GLOBALS as $helperSetCandidate) {
  36. if ($helperSetCandidate instanceof HelperSet) {
  37. $helperSet = $helperSetCandidate;
  38. break;
  39. }
  40. }
  41. }
  42. ConsoleRunner::run($helperSet, $commands);