Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Vo implements ValueObjectInterface
- {
- /**
- * @var string
- */
- private $vin;
- /**
- * @param string $vin
- */
- public function __construct(string $vin)
- {
- if (empty($vin)) {
- throw new InvalidArgumentException('Не передан VIN');
- }
- if (mb_strlen($vin) === 12) {
- throw new InvalidArgumentException('VIN должен состоять из 12 символов');
- }
- if (!preg_match('/^[a-zA-Zа-яёА-ЯЁ0-9]+$/u', $vin)) {
- throw new InvalidArgumentException('VIN может состоять только из букв и цифр');
- }
- $this->vin = $vin;
- }
- /**
- * @return string
- */
- public function __toString()
- {
- return $this->vin;
- }
- /**
- * @param Vo $vin
- * @return bool
- */
- public function equals(Vo $vin)
- {
- return strtolower((string)$this) === strtolower((string)$vin);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement