ColumnSchemaBuilder.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\db\mysql;
  8. use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;
  9. /**
  10. * ColumnSchemaBuilder is the schema builder for MySQL databases.
  11. *
  12. * @author Chris Harris <chris@buckshotsoftware.com>
  13. * @since 2.0.8
  14. */
  15. class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function buildUnsignedString()
  21. {
  22. return $this->isUnsigned ? ' UNSIGNED' : '';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function buildAfterString()
  28. {
  29. return $this->after !== null ?
  30. ' AFTER ' . $this->db->quoteColumnName($this->after) :
  31. '';
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. protected function buildFirstString()
  37. {
  38. return $this->isFirst ? ' FIRST' : '';
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function buildCommentString()
  44. {
  45. return $this->comment !== null ? ' COMMENT ' . $this->db->quoteValue($this->comment) : '';
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function __toString()
  51. {
  52. switch ($this->getTypeCategory()) {
  53. case self::CATEGORY_PK:
  54. $format = '{type}{length}{comment}{check}{append}{pos}';
  55. break;
  56. case self::CATEGORY_NUMERIC:
  57. $format = '{type}{length}{unsigned}{notnull}{unique}{default}{comment}{check}{append}{pos}';
  58. break;
  59. default:
  60. $format = '{type}{length}{notnull}{unique}{default}{comment}{check}{append}{pos}';
  61. }
  62. return $this->buildCompleteString($format);
  63. }
  64. }