phar-cli-stub.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the LGPL. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. Phar::mapPhar();
  20. require_once 'phar://'.__FILE__.'/Doctrine/Common/ClassLoader.php';
  21. $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', 'phar://'.__FILE__);
  22. $classLoader->register();
  23. $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', 'phar://'.__FILE__);
  24. $classLoader->register();
  25. $classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'phar://'.__FILE__);
  26. $classLoader->register();
  27. // Support for using the Doctrine ORM convention of providing a `cli-config.php` file.
  28. $configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php';
  29. $helperSet = null;
  30. if (file_exists($configFile)) {
  31. if ( ! is_readable($configFile)) {
  32. trigger_error(
  33. 'Configuration file [' . $configFile . '] does not have read permission.', E_ERROR
  34. );
  35. }
  36. require $configFile;
  37. foreach ($GLOBALS as $helperSetCandidate) {
  38. if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
  39. $helperSet = $helperSetCandidate;
  40. break;
  41. }
  42. }
  43. }
  44. $helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet();
  45. $helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
  46. $cli = new \Symfony\Component\Console\Application('Doctrine Migrations', \Doctrine\DBAL\Migrations\MigrationsVersion::VERSION);
  47. $cli->setCatchExceptions(true);
  48. $cli->setHelperSet($helperSet);
  49. $cli->addCommands(array(
  50. // Migrations Commands
  51. new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
  52. new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
  53. new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
  54. new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
  55. new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
  56. ));
  57. if ($helperSet->has('em')) {
  58. $cli->add(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand());
  59. }
  60. $input = file_exists('migrations-input.php')
  61. ? include('migrations-input.php')
  62. : null;
  63. $output = file_exists('migrations-output.php')
  64. ? include('migrations-output.php')
  65. : null;
  66. $cli->run($input, $output);
  67. __HALT_COMPILER();