doctrine-dbal.php 1.5 KB

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