-
Notifications
You must be signed in to change notification settings - Fork 22
Refactor Module Templates to use DTOs in Services and Controllers #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
armanist
merged 3 commits into
softberg:master
from
armanist:443-Implement-DTO-Pattern-for-Posts-Comments-and-Users-for-module-templates
Apr 2, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,92 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Quantum PHP Framework | ||
| * | ||
| * An open source software development framework for PHP | ||
| * | ||
| * @package Quantum | ||
| * @author Arman Ag. <arman.ag@softberg.org> | ||
| * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) | ||
| * @link http://quantum.softberg.org/ | ||
| * @since 3.0.0 | ||
| */ | ||
|
|
||
| namespace {{MODULE_NAMESPACE}}\DTOs; | ||
|
|
||
| use Quantum\Http\Request; | ||
|
|
||
| /** | ||
| * Class CommentDTO | ||
| * @package {{MODULE_NAMESPACE}}\DTOs | ||
| */ | ||
| class CommentDTO | ||
| { | ||
| /** | ||
| * @var string | ||
| */ | ||
| private string $postUuid; | ||
|
|
||
| /** | ||
| * @var string | ||
| */ | ||
| private string $userUuid; | ||
|
|
||
| /** | ||
| * @var string | ||
| */ | ||
| private string $content; | ||
|
|
||
| /** | ||
| * @param string $postUuid | ||
| * @param string $userUuid | ||
| * @param string $content | ||
| */ | ||
| public function __construct( | ||
| string $postUuid, | ||
| string $userUuid, | ||
| string $content | ||
| ) { | ||
| $this->postUuid = $postUuid; | ||
| $this->userUuid = $userUuid; | ||
| $this->content = $content; | ||
| } | ||
|
|
||
| /** | ||
| * @param Request $request | ||
| * @param string $postUuid | ||
| * @param string $userUuid | ||
| * @return self | ||
| */ | ||
| public static function fromRequest(Request $request, string $postUuid, string $userUuid): self | ||
| { | ||
| return new self($postUuid, $userUuid, trim((string)$request->get('content'))); | ||
| } | ||
|
|
||
| public function getPostUuid(): string | ||
| { | ||
| return $this->postUuid; | ||
| } | ||
|
|
||
| public function getUserUuid(): string | ||
| { | ||
| return $this->userUuid; | ||
| } | ||
|
|
||
| public function getContent(): string | ||
| { | ||
| return $this->content; | ||
| } | ||
|
|
||
| /** | ||
| * @return array | ||
| */ | ||
| public function toArray(): array | ||
| { | ||
| return [ | ||
| 'post_uuid' => $this->postUuid, | ||
| 'user_uuid' => $this->userUuid, | ||
| 'content' => $this->content, | ||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or 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,113 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Quantum PHP Framework | ||
| * | ||
| * An open source software development framework for PHP | ||
| * | ||
| * @package Quantum | ||
| * @author Arman Ag. <arman.ag@softberg.org> | ||
| * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) | ||
| * @link http://quantum.softberg.org/ | ||
| * @since 3.0.0 | ||
| */ | ||
|
|
||
| namespace {{MODULE_NAMESPACE}}\DTOs; | ||
|
|
||
| use Quantum\Http\Request; | ||
|
|
||
| /** | ||
| * Class PostDTO | ||
| * @package {{MODULE_NAMESPACE}}\DTOs | ||
| */ | ||
| class PostDTO | ||
| { | ||
| /** | ||
| * @var string | ||
| */ | ||
| private string $title; | ||
|
|
||
| /** | ||
| * @var string | ||
| */ | ||
| private string $content; | ||
|
|
||
| /** | ||
| * @var string|null | ||
| */ | ||
| private ?string $userUuid; | ||
|
|
||
| /** | ||
| * @var string|null | ||
| */ | ||
| private ?string $image; | ||
|
|
||
| /** | ||
| * @param string $title | ||
| * @param string $content | ||
| * @param string|null $userUuid | ||
| * @param string|null $image | ||
| */ | ||
| public function __construct( | ||
| string $title, | ||
| string $content, | ||
| ?string $userUuid = null, | ||
| ?string $image = null | ||
| ) { | ||
| $this->title = $title; | ||
| $this->content = $content; | ||
| $this->userUuid = $userUuid; | ||
| $this->image = $image; | ||
| } | ||
|
|
||
| /** | ||
| * @param Request $request | ||
| * @param string|null $userUuid | ||
| * @param string|null $image | ||
| * @return self | ||
| */ | ||
| public static function fromRequest(Request $request, ?string $userUuid = null, ?string $image = null): self | ||
| { | ||
| return new self( | ||
| $request->get('title', null, true), | ||
| $request->get('content', null, true), | ||
| $userUuid, | ||
| $image | ||
| ); | ||
| } | ||
|
|
||
| public function getTitle(): string | ||
| { | ||
| return $this->title; | ||
| } | ||
|
|
||
| public function getContent(): string | ||
| { | ||
| return $this->content; | ||
| } | ||
|
|
||
| public function getUserUuid(): ?string | ||
| { | ||
| return $this->userUuid; | ||
| } | ||
|
|
||
| public function getImage(): ?string | ||
| { | ||
| return $this->image; | ||
| } | ||
|
|
||
| /** | ||
| * @return array | ||
| */ | ||
| public function toArray(): array | ||
| { | ||
| return array_filter([ | ||
| 'user_uuid' => $this->userUuid, | ||
| 'title' => $this->title, | ||
| 'content' => $this->content, | ||
| 'image' => $this->image, | ||
| ], function ($value) { | ||
| return $value !== null; | ||
| }); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.