Created
January 10, 2019 14:34
-
-
Save BerezhniyDmitro/8013e4730fb358414457140bf55943e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: maestro | |
* Date: 26.03.18 | |
* Time: 11:26 | |
*/ | |
namespace App\ValueObject\Id; | |
use InvalidArgumentException; | |
/** | |
* Class Id | |
*/ | |
class Id | |
{ | |
/** | |
* @var int $id id Лида | |
*/ | |
protected $id; | |
/** | |
* Name constructor. | |
* | |
* @param int $id id | |
*/ | |
private function __construct($id) | |
{ | |
$isSuccess = filter_var($id, FILTER_VALIDATE_INT, [ | |
'options' => [ | |
'min_range' => 1 | |
] | |
]); | |
if (! $isSuccess) { | |
throw new InvalidArgumentException(sprintf('Bad id %d', $id)); | |
} | |
$this->id = (int)$id; | |
} | |
/** | |
* Метод инстанцирует обьект | |
* | |
* @param int $id инстанцирует обьект | |
* | |
* @return Id | |
*/ | |
public static function create($id) | |
{ | |
return new static($id); | |
} | |
/** | |
* @return string | |
*/ | |
public function __toString() | |
{ | |
return $this->get(); | |
} | |
/** | |
* @return string | |
*/ | |
public function get() | |
{ | |
return $this->id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment