Last active
November 11, 2022 11:53
-
-
Save maxloncar/ba8ab42df55c0cee896b9063c30a26d1 to your computer and use it in GitHub Desktop.
Message class
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 | |
// src/User/Message/CreateUserMessage.php | |
namespace App\User\Message; | |
use Assert\Assert; | |
use Symfony\Component\HttpFoundation\Request; | |
/** | |
* Class CreateUserMessage | |
* | |
* @package App\User\Message | |
* @author DEVŌT <devot.team> | |
*/ | |
class CreateUserMessage | |
{ | |
/** | |
* CreateUserMessage constructor | |
* | |
* @param int $id | |
*/ | |
private function __construct(private int $id) | |
{ | |
} | |
/** | |
* @param Request $request | |
* @return CreateUserMessage | |
*/ | |
public static function fromRequest(Request $request): self | |
{ | |
$body = $request->request; | |
/** @var string $id */ | |
$id = $body->get('id'); | |
$assert = Assert::lazy(); | |
$assert->that($id, self::class) | |
->notBlank() | |
->integer(); | |
$assert->verifyNow(); | |
return new self($id); | |
} | |
/** | |
* @return int | |
*/ | |
public function id(): int | |
{ | |
return $this->id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment