-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
see: #30
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Service\User; | ||
|
||
final class UserDTO | ||
{ | ||
public function __construct( | ||
private string $email = '', | ||
private ?string $slug = null, | ||
private array $projects = [], | ||
) { | ||
} | ||
|
||
public function getSlug(): ?string | ||
{ | ||
return $this->slug; | ||
} | ||
|
||
public function setSlug(string $slug): self | ||
{ | ||
$this->slug = $slug; | ||
|
||
return $this; | ||
} | ||
|
||
public function getEmail(): ?string | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public function setEmail(string $email): self | ||
{ | ||
$this->email = $email; | ||
|
||
return $this; | ||
} | ||
|
||
public function getProjects(): array | ||
{ | ||
return $this->projects; | ||
} | ||
|
||
public function setProjects(array $projects): self | ||
{ | ||
$this->projects = $projects; | ||
|
||
return $this; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Service\User; | ||
|
||
use App\Entity\User; | ||
use Symfony\Component\Serializer\Encoder\JsonEncoder; | ||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; | ||
use Symfony\Component\Serializer\Serializer; | ||
|
||
final class UserMapper | ||
{ | ||
/** @throws ExceptionInterface */ | ||
public static function fromEntityToJson(User $user): mixed | ||
{ | ||
$dto = self::fromEntityToDTO($user); | ||
$serializer = new Serializer([new ObjectNormalizer()]); | ||
|
||
return $serializer->normalize($dto, JsonEncoder::FORMAT); | ||
} | ||
|
||
public static function fromEntityToDTO(User $user): UserDTO | ||
{ | ||
return new UserDTO( | ||
$user->getEmail(), | ||
$user->getSlug(), | ||
// UserHelper::getCategoriesArrayFromUser($user) | ||
); | ||
} | ||
} |