Dimensions.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace Illuminate\Validation\Rules;
  3. class Dimensions
  4. {
  5. /**
  6. * The constraints for the dimensions rule.
  7. *
  8. * @var array
  9. */
  10. protected $constraints = [];
  11. /**
  12. * Create a new dimensions rule instance.
  13. *
  14. * @param array $constraints;
  15. * @return void
  16. */
  17. public function __construct(array $constraints = [])
  18. {
  19. $this->constraints = $constraints;
  20. }
  21. /**
  22. * Set the "width" constraint.
  23. *
  24. * @param int $value
  25. * @return $this
  26. */
  27. public function width($value)
  28. {
  29. $this->constraints['width'] = $value;
  30. return $this;
  31. }
  32. /**
  33. * Set the "height" constraint.
  34. *
  35. * @param int $value
  36. * @return $this
  37. */
  38. public function height($value)
  39. {
  40. $this->constraints['height'] = $value;
  41. return $this;
  42. }
  43. /**
  44. * Set the "min width" constraint.
  45. *
  46. * @param int $value
  47. * @return $this
  48. */
  49. public function minWidth($value)
  50. {
  51. $this->constraints['min_width'] = $value;
  52. return $this;
  53. }
  54. /**
  55. * Set the "min height" constraint.
  56. *
  57. * @param int $value
  58. * @return $this
  59. */
  60. public function minHeight($value)
  61. {
  62. $this->constraints['min_height'] = $value;
  63. return $this;
  64. }
  65. /**
  66. * Set the "max width" constraint.
  67. *
  68. * @param int $value
  69. * @return $this
  70. */
  71. public function maxWidth($value)
  72. {
  73. $this->constraints['max_width'] = $value;
  74. return $this;
  75. }
  76. /**
  77. * Set the "max height" constraint.
  78. *
  79. * @param int $value
  80. * @return $this
  81. */
  82. public function maxHeight($value)
  83. {
  84. $this->constraints['max_height'] = $value;
  85. return $this;
  86. }
  87. /**
  88. * Set the "ratio" constraint.
  89. *
  90. * @param float $value
  91. * @return $this
  92. */
  93. public function ratio($value)
  94. {
  95. $this->constraints['ratio'] = $value;
  96. return $this;
  97. }
  98. /**
  99. * Convert the rule to a validation string.
  100. *
  101. * @return string
  102. */
  103. public function __toString()
  104. {
  105. $result = '';
  106. foreach ($this->constraints as $key => $value) {
  107. $result .= "$key=$value,";
  108. }
  109. return 'dimensions:'.substr($result, 0, -1);
  110. }
  111. }