doctrine-dbal.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. use Doctrine\DBAL\Tools\Console\ConsoleRunner;
  3. fwrite(
  4. STDERR,
  5. '[Warning] The use of this script is discouraged.'
  6. . ' You find instructions on how to bootstrap the console runner in our documentation.'
  7. . PHP_EOL,
  8. );
  9. echo PHP_EOL . PHP_EOL;
  10. $files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'];
  11. $loader = null;
  12. $cwd = getcwd();
  13. $directories = [$cwd, $cwd . DIRECTORY_SEPARATOR . 'config'];
  14. $configFile = null;
  15. foreach ($files as $file) {
  16. if (file_exists($file)) {
  17. $loader = require $file;
  18. break;
  19. }
  20. }
  21. if (! $loader) {
  22. throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?');
  23. }
  24. foreach ($directories as $directory) {
  25. $configFile = $directory . DIRECTORY_SEPARATOR . 'cli-config.php';
  26. if (file_exists($configFile)) {
  27. break;
  28. }
  29. }
  30. if (! file_exists($configFile)) {
  31. ConsoleRunner::printCliConfigTemplate();
  32. exit(1);
  33. }
  34. if (! is_readable($configFile)) {
  35. echo 'Configuration file [' . $configFile . '] does not have read permission.' . PHP_EOL;
  36. exit(1);
  37. }
  38. $commands = [];
  39. $connectionProvider = require $configFile;
  40. ConsoleRunner::run($connectionProvider, $commands);