MigrationException.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. namespace Doctrine\DBAL\Migrations;
  20. use \Doctrine\DBAL\Migrations\Finder\MigrationFinderInterface;
  21. /**
  22. * Class for Migrations specific exceptions
  23. *
  24. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  25. * @link www.doctrine-project.org
  26. * @since 2.0
  27. * @author Jonathan H. Wage <jonwage@gmail.com>
  28. */
  29. class MigrationException extends \Exception
  30. {
  31. public static function migrationsNamespaceRequired()
  32. {
  33. return new self('Migrations namespace must be configured in order to use Doctrine migrations.', 2);
  34. }
  35. public static function migrationsDirectoryRequired()
  36. {
  37. return new self('Migrations directory must be configured in order to use Doctrine migrations.', 3);
  38. }
  39. public static function noMigrationsToExecute()
  40. {
  41. return new self('Could not find any migrations to execute.', 4);
  42. }
  43. public static function unknownMigrationVersion($version)
  44. {
  45. return new self(sprintf('Could not find migration version %s', $version), 5);
  46. }
  47. public static function alreadyAtVersion($version)
  48. {
  49. return new self(sprintf('Database is already at version %s', $version), 6);
  50. }
  51. public static function duplicateMigrationVersion($version, $class)
  52. {
  53. return new self(sprintf('Migration version %s already registered with class %s', $version, $class), 7);
  54. }
  55. public static function configurationFileAlreadyLoaded()
  56. {
  57. return new self(sprintf('Migrations configuration file already loaded'), 8);
  58. }
  59. public static function configurationIncompatibleWithFinder(
  60. $configurationParameterName,
  61. MigrationFinderInterface $finder
  62. ) {
  63. return new self(
  64. sprintf(
  65. 'Configuration-parameter "%s" cannot be used with finder of type "%s"',
  66. $configurationParameterName,
  67. get_class($finder)
  68. ),
  69. 9
  70. );
  71. }
  72. public static function configurationNotValid($msg)
  73. {
  74. return new self($msg, 10);
  75. }
  76. /**
  77. * @param string $migrationClass
  78. * @param string $migrationNamespace
  79. * @return MigrationException
  80. */
  81. public static function migrationClassNotFound($migrationClass, $migrationNamespace)
  82. {
  83. return new self(
  84. sprintf(
  85. 'Migration class "%s" was not found. Is it placed in "%s" namespace?',
  86. $migrationClass,
  87. $migrationNamespace
  88. )
  89. );
  90. }
  91. /**
  92. * @param string $migrationClass
  93. * @return MigrationException
  94. */
  95. public static function migrationNotConvertibleToSql($migrationClass)
  96. {
  97. return new self(
  98. sprintf(
  99. 'Migration class "%s" contains a prepared statement.
  100. Unfortunately there is no cross platform way of outputing it as an sql string.
  101. Do you want to write a PR for it ?',
  102. $migrationClass
  103. )
  104. );
  105. }
  106. }