Initial project structure with Slim skeleton
This commit is contained in:
56
src/Domain/User/User.php
Normal file
56
src/Domain/User/User.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Domain\User;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
class User implements JsonSerializable
|
||||
{
|
||||
private ?int $id;
|
||||
|
||||
private string $username;
|
||||
|
||||
private string $firstName;
|
||||
|
||||
private string $lastName;
|
||||
|
||||
public function __construct(?int $id, string $username, string $firstName, string $lastName)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->username = strtolower($username);
|
||||
$this->firstName = ucfirst($firstName);
|
||||
$this->lastName = ucfirst($lastName);
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUsername(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getFirstName(): string
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
public function getLastName(): string
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'username' => $this->username,
|
||||
'firstName' => $this->firstName,
|
||||
'lastName' => $this->lastName,
|
||||
];
|
||||
}
|
||||
}
|
11
src/Domain/User/UserNotFoundException.php
Normal file
11
src/Domain/User/UserNotFoundException.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Domain\User;
|
||||
|
||||
use App\Domain\DomainException\DomainRecordNotFoundException;
|
||||
|
||||
class UserNotFoundException extends DomainRecordNotFoundException
|
||||
{
|
||||
public $message = 'The user you requested does not exist.';
|
||||
}
|
19
src/Domain/User/UserRepository.php
Normal file
19
src/Domain/User/UserRepository.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Domain\User;
|
||||
|
||||
interface UserRepository
|
||||
{
|
||||
/**
|
||||
* @return User[]
|
||||
*/
|
||||
public function findAll(): array;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return User
|
||||
* @throws UserNotFoundException
|
||||
*/
|
||||
public function findUserOfId(int $id): User;
|
||||
}
|
Reference in New Issue
Block a user