SchemaException.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Doctrine\DBAL\Schema;
  3. class SchemaException extends \Doctrine\DBAL\DBALException
  4. {
  5. const TABLE_DOESNT_EXIST = 10;
  6. const TABLE_ALREADY_EXISTS = 20;
  7. const COLUMN_DOESNT_EXIST = 30;
  8. const COLUMN_ALREADY_EXISTS = 40;
  9. const INDEX_DOESNT_EXIST = 50;
  10. const INDEX_ALREADY_EXISTS = 60;
  11. const SEQUENCE_DOENST_EXIST = 70;
  12. const SEQUENCE_ALREADY_EXISTS = 80;
  13. const INDEX_INVALID_NAME = 90;
  14. const FOREIGNKEY_DOESNT_EXIST = 100;
  15. /**
  16. * @param string $tableName
  17. * @return SchemaException
  18. */
  19. static public function tableDoesNotExist($tableName)
  20. {
  21. return new self("There is no table with name '".$tableName."' in the schema.", self::TABLE_DOESNT_EXIST);
  22. }
  23. /**
  24. * @param string $indexName
  25. * @return SchemaException
  26. */
  27. static public function indexNameInvalid($indexName)
  28. {
  29. return new self("Invalid index-name $indexName given, has to be [a-zA-Z0-9_]", self::INDEX_INVALID_NAME);
  30. }
  31. /**
  32. * @param string $indexName
  33. * @return SchemaException
  34. */
  35. static public function indexDoesNotExist($indexName, $table)
  36. {
  37. return new self("Index '$indexName' does not exist on table '$table'.", self::INDEX_DOESNT_EXIST);
  38. }
  39. /**
  40. * @param string $indexName
  41. * @return SchemaException
  42. */
  43. static public function indexAlreadyExists($indexName, $table)
  44. {
  45. return new self("An index with name '$indexName' was already defined on table '$table'.", self::INDEX_ALREADY_EXISTS);
  46. }
  47. /**
  48. * @param string $columnName
  49. * @return SchemaException
  50. */
  51. static public function columnDoesNotExist($columnName, $table)
  52. {
  53. return new self("There is no column with name '$columnName' on table '$table'.", self::COLUMN_DOESNT_EXIST);
  54. }
  55. /**
  56. *
  57. * @param string $tableName
  58. * @return SchemaException
  59. */
  60. static public function tableAlreadyExists($tableName)
  61. {
  62. return new self("The table with name '".$tableName."' already exists.", self::TABLE_ALREADY_EXISTS);
  63. }
  64. /**
  65. *
  66. * @param string $tableName
  67. * @param string $columnName
  68. * @return SchemaException
  69. */
  70. static public function columnAlreadyExists($tableName, $columnName)
  71. {
  72. return new self(
  73. "The column '".$columnName."' on table '".$tableName."' already exists.", self::COLUMN_ALREADY_EXISTS
  74. );
  75. }
  76. /**
  77. * @param string $sequenceName
  78. * @return SchemaException
  79. */
  80. static public function sequenceAlreadyExists($sequenceName)
  81. {
  82. return new self("The sequence '".$sequenceName."' already exists.", self::SEQUENCE_ALREADY_EXISTS);
  83. }
  84. /**
  85. * @param string $sequenceName
  86. * @return SchemaException
  87. */
  88. static public function sequenceDoesNotExist($sequenceName)
  89. {
  90. return new self("There exists no sequence with the name '".$sequenceName."'.", self::SEQUENCE_DOENST_EXIST);
  91. }
  92. /**
  93. * @param string $fkName
  94. * @return SchemaException
  95. */
  96. static public function foreignKeyDoesNotExist($fkName, $table)
  97. {
  98. return new self("There exists no foreign key with the name '$fkName' on table '$table'.", self::FOREIGNKEY_DOESNT_EXIST);
  99. }
  100. static public function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey)
  101. {
  102. return new self(
  103. "The performed schema operation on ".$localTable->getName()." requires a named foreign key, ".
  104. "but the given foreign key from (".implode(", ", $foreignKey->getColumns()).") onto foreign table ".
  105. "'".$foreignKey->getForeignTableName()."' (".implode(", ", $foreignKey->getForeignColumns()).") is currently ".
  106. "unnamed."
  107. );
  108. }
  109. static public function alterTableChangeNotSupported($changeName) {
  110. return new self ("Alter table change not supported, given '$changeName'");
  111. }
  112. }