rangable_rule.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php namespace System\Validation;
  2. abstract class Rangable_Rule extends Nullable_Rule {
  3. /**
  4. * The exact size the attribute must be.
  5. *
  6. * @var int
  7. */
  8. public $size;
  9. /**
  10. * The maximum size of the attribute.
  11. *
  12. * @var int
  13. */
  14. public $maximum;
  15. /**
  16. * The minimum size of the attribute.
  17. *
  18. * @var int
  19. */
  20. public $minimum;
  21. /**
  22. * The "wrong size" error message.
  23. *
  24. * @var string
  25. */
  26. public $wrong_size;
  27. /**
  28. * The "too big" error message.
  29. *
  30. * @var string
  31. */
  32. public $too_big;
  33. /**
  34. * The "too small" error message.
  35. *
  36. * @var string
  37. */
  38. public $too_small;
  39. /**
  40. * Set the exact size the attribute must be.
  41. *
  42. * @param int $size
  43. * @return Rangable_Rule
  44. */
  45. public function is($size)
  46. {
  47. $this->size = $size;
  48. return $this;
  49. }
  50. /**
  51. * Set the minimum and maximum size of the attribute.
  52. *
  53. * @param int $minimum
  54. * @param int $maximum
  55. * @return Rangable_Rule
  56. */
  57. public function between($minimum, $maximum)
  58. {
  59. $this->minimum = $minimum;
  60. $this->maximum = $maximum;
  61. return $this;
  62. }
  63. /**
  64. * Set the minimum size the attribute.
  65. *
  66. * @param int $minimum
  67. * @return Rangable_Rule
  68. */
  69. public function minimum($minimum)
  70. {
  71. $this->minimum = $minimum;
  72. return $this;
  73. }
  74. /**
  75. * Set the maximum size the attribute.
  76. *
  77. * @param int $maximum
  78. * @return Rangable_Rule
  79. */
  80. public function maximum($maximum)
  81. {
  82. $this->maximum = $maximum;
  83. return $this;
  84. }
  85. /**
  86. * Set the validation error message.
  87. *
  88. * @param string $message
  89. * @return Rangable_Rule
  90. */
  91. public function message($message)
  92. {
  93. return $this->wrong_size($message)->too_big($message)->too_small($message);
  94. }
  95. /**
  96. * Set the "wrong size" error message.
  97. *
  98. * @param string $message
  99. * @return Rangable_Rule
  100. */
  101. public function wrong_size($message)
  102. {
  103. $this->wrong_size = $message;
  104. return $this;
  105. }
  106. /**
  107. * Set the "too big" error message.
  108. *
  109. * @param string $message
  110. * @return Rangable_Rule
  111. */
  112. public function too_big($message)
  113. {
  114. $this->too_big = $message;
  115. return $this;
  116. }
  117. /**
  118. * Set the "too small" error message.
  119. *
  120. * @param string $message
  121. * @return Rangable_Rule
  122. */
  123. public function too_small($message)
  124. {
  125. $this->too_small = $message;
  126. return $this;
  127. }
  128. }