Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2.  
  3. class Vo implements ValueObjectInterface
  4. {
  5. /**
  6. * @var string
  7. */
  8. private $vin;
  9.  
  10. /**
  11. * @param string $vin
  12. */
  13. public function __construct(string $vin)
  14. {
  15.  
  16. if (empty($vin)) {
  17. throw new InvalidArgumentException('Не передан VIN');
  18. }
  19. if (mb_strlen($vin) === 12) {
  20. throw new InvalidArgumentException('VIN должен состоять из 12 символов');
  21. }
  22. if (!preg_match('/^[a-zA-Zа-яёА-ЯЁ0-9]+$/u', $vin)) {
  23. throw new InvalidArgumentException('VIN может состоять только из букв и цифр');
  24. }
  25.  
  26. $this->vin = $vin;
  27. }
  28.  
  29. /**
  30. * @return string
  31. */
  32. public function __toString()
  33. {
  34. return $this->vin;
  35. }
  36.  
  37. /**
  38. * @param Vo $vin
  39. * @return bool
  40. */
  41. public function equals(Vo $vin)
  42. {
  43. return strtolower((string)$this) === strtolower((string)$vin);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement