Skip to content

Instantly share code, notes, and snippets.

@BerezhniyDmitro
Created January 10, 2019 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BerezhniyDmitro/8013e4730fb358414457140bf55943e8 to your computer and use it in GitHub Desktop.
Save BerezhniyDmitro/8013e4730fb358414457140bf55943e8 to your computer and use it in GitHub Desktop.
<?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