PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/propel/generator/lib/model/ColumnDefaultValue.php

https://bitbucket.org/bayrock/gw2spidy
PHP | 114 lines | 49 code | 14 blank | 51 comment | 8 complexity | 36b9fb8d7ec34b56a94e63d8e4b21f0f MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. /**
  10. * A class for holding a column default value.
  11. *
  12. * @author Hans Lellelid <hans@xmpl.org>
  13. * @version $Revision$
  14. * @package propel.generator.model
  15. */
  16. class ColumnDefaultValue
  17. {
  18. const TYPE_VALUE = "value";
  19. const TYPE_EXPR = "expr";
  20. /**
  21. * @var string The default value, as specified in the schema.
  22. */
  23. private $value;
  24. /**
  25. * @var string The type of value represented by this object (DefaultValue::TYPE_VALUE or DefaultValue::TYPE_EXPR).
  26. */
  27. private $type = ColumnDefaultValue::TYPE_VALUE;
  28. /**
  29. * Creates a new DefaultValue object.
  30. *
  31. * @param string $value The default value, as specified in the schema.
  32. * @param string $type The type of default value (DefaultValue::TYPE_VALUE or DefaultValue::TYPE_EXPR)
  33. */
  34. public function __construct($value, $type = null)
  35. {
  36. $this->setValue($value);
  37. if ($type !== null) {
  38. $this->setType($type);
  39. }
  40. }
  41. /**
  42. * @return string The type of default value (DefaultValue::TYPE_VALUE or DefaultValue::TYPE_EXPR)
  43. */
  44. public function getType()
  45. {
  46. return $this->type;
  47. }
  48. /**
  49. * @param string $type The type of default value (DefaultValue::TYPE_VALUE or DefaultValue::TYPE_EXPR)
  50. */
  51. public function setType($type)
  52. {
  53. $this->type = $type;
  54. }
  55. /**
  56. * Convenience method to indicate whether the value in this object is an expression (as opposed to simple value).
  57. *
  58. * @return boolean Whether value this object holds is an expression.
  59. */
  60. public function isExpression()
  61. {
  62. return ($this->type == self::TYPE_EXPR);
  63. }
  64. /**
  65. * @return string The value, as specified in the schema.
  66. */
  67. public function getValue()
  68. {
  69. return $this->value;
  70. }
  71. /**
  72. * @param string $value The value, as specified in the schema.
  73. */
  74. public function setValue($value)
  75. {
  76. $this->value = $value;
  77. }
  78. /**
  79. * A method to compare if two Default values match
  80. *
  81. * @param ColumnDefaultValue $other The value to compare to
  82. * @return boolean Wheter this object represents same default value as $other
  83. * @author Niklas Närhinen <niklas@narhinen.net>
  84. */
  85. public function equals(ColumnDefaultValue $other)
  86. {
  87. if ($this->getType() != $other->getType()) {
  88. return false;
  89. }
  90. if ($this == $other) {
  91. return true;
  92. }
  93. // special case for current timestamp
  94. $equivalents = array('CURRENT_TIMESTAMP', 'NOW()');
  95. if (in_array(strtoupper($this->getValue()), $equivalents) && in_array(strtoupper($other->getValue()), $equivalents)) {
  96. return true;
  97. }
  98. return false; // Can't help, they are different
  99. }
  100. }