From b908dc6ea394cf9dd89d75b6d61952fd2bb4f39f Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Thu, 23 May 2024 21:24:57 -0400 Subject: [PATCH] Add an Entity trait, format the example RSS feed, work on the Repository patterns. --- app/src/Domain/Entity.php | 43 ++++++++++ app/src/Domain/{Model => Entity}/Channel.php | 2 +- app/src/Domain/{Model => Entity}/User.php | 27 ++++--- app/src/Domain/Repository/UserRepository.php | 79 +++++++++++++++++++ .../Repository/UserRepositoryInterface.php | 13 +++ app/src/Exception/EntityNotFoundException.php | 7 ++ etc/example-podbean-rss.xml | 9 ++- 7 files changed, 167 insertions(+), 13 deletions(-) create mode 100644 app/src/Domain/Entity.php rename app/src/Domain/{Model => Entity}/Channel.php (97%) rename app/src/Domain/{Model => Entity}/User.php (69%) create mode 100644 app/src/Domain/Repository/UserRepository.php create mode 100644 app/src/Domain/Repository/UserRepositoryInterface.php create mode 100644 app/src/Exception/EntityNotFoundException.php diff --git a/app/src/Domain/Entity.php b/app/src/Domain/Entity.php new file mode 100644 index 0000000..d88b7f4 --- /dev/null +++ b/app/src/Domain/Entity.php @@ -0,0 +1,43 @@ +id = $id; + } + + public function getId(): int + { + return $this->id; + } + + public function setCreatedAt(DateTimeImmutable $createdAt): void + { + $this->createdAt = $createdAt; + } + + public function getCreatedAt(): DateTimeImmutable + { + return $this->createdAt; + } + + public function setUpdatedAt(DateTime $updatedAt): void + { + $this->updatedAt = $updatedAt; + } + + public function getUpdatedAt(): DateTime + { + return $this->updatedAt; + } +} diff --git a/app/src/Domain/Model/Channel.php b/app/src/Domain/Entity/Channel.php similarity index 97% rename from app/src/Domain/Model/Channel.php rename to app/src/Domain/Entity/Channel.php index 66cf65f..f8f6369 100644 --- a/app/src/Domain/Model/Channel.php +++ b/app/src/Domain/Entity/Channel.php @@ -1,6 +1,6 @@ email = $email; - $this->password = $password; - $this->name; - } + ) { } public function getEmail(): string { @@ -37,7 +36,7 @@ class User */ public function isNew(): bool { - return (bool) $this->id; + return (bool) $this->getId(); } /** @@ -46,11 +45,19 @@ class User */ public static function fromArray(array $props): User { - return new self( - $props['id'] ?? null, + $user = new self( $props['email'], $props['password'], $props['name'] ); + + if ($props['id']) { + $user->setId($props['id']); + } + + $user->setCreatedAt($props['createdAt']); + $user->setUpdatedAt($props['updatedAt']); + + return $user; } } diff --git a/app/src/Domain/Repository/UserRepository.php b/app/src/Domain/Repository/UserRepository.php new file mode 100644 index 0000000..a2cd438 --- /dev/null +++ b/app/src/Domain/Repository/UserRepository.php @@ -0,0 +1,79 @@ + $results['id'], + 'email' => $results['email'], + 'password' => $results['password'], + 'name' => $results['name'], + 'createdAt' => $results['created_at'], + 'updatedAt' => $results['updated_at'] + ]); + } + + /** + * @param string $query The Query for getting a User + * @param arary $params The parameters in the query + * @param PDO $connection The PDO connection + * @return array The column data from the Database + * @throws EntityNotFoundException The User does no exist + */ + protected function queryForUser( + string $query, + array $params, + PDO $connection + ): array { + $statement = $connection->prepare($query); + $statement->execute($params); + $results = $statement->fetchAll(); + + if (!$results) { + throw new EntityNotFoundException("Unable to find User"); + } + + return array_shift($results); + } + + public function get(int $id): User + { + $query = "SELECT * FROM users WHERE id = :id LIMIT 1"; + $connection = $this->database->getConnection(); + $userData = $this->queryForUser( + $query, + [ 'id' => $id ], + $connection + ); + return $this->userFromQueryResults($userData); + } + + public function getFromEmail(string $email): User + { + $query = "SELECT * FROM users WHERE email = :email LIMIT 1"; + $connection = $this->database->getConnection(); + $userData = $this->queryForUser( + $query, + [ 'email' => $email ], + $connection + ); + return $this->userFromQueryResults($userData); + } +} diff --git a/app/src/Domain/Repository/UserRepositoryInterface.php b/app/src/Domain/Repository/UserRepositoryInterface.php new file mode 100644 index 0000000..e01503e --- /dev/null +++ b/app/src/Domain/Repository/UserRepositoryInterface.php @@ -0,0 +1,13 @@ +https://kevyscountrybreakfast.podbean.com/e/episode-5-sarasota-sizzle/#comments Tue, 12 May 2020 21:30:08 -0300 kevyscountrybreakfast.podbean.com/d7b42df5-ecf9-593a-803f-40d3a054cc6f - Ah, the sounds of spring. Birds chirping, dogs grilling, and the triumphant return of Kevys Country Breakfast. Join us for an all access guided tour as the Princes of Pod prepare to reclaim their crown of audio royalty. Plus, Taiwanese Baseball and Dave’s perverted palate.

]]>
- Ah, the sounds of spring. Birds chirping, dogs grilling, and the triumphant return of Kevys Country Breakfast. Join us for an all access guided tour as the Princes of Pod prepare to reclaim their crown of audio royalty. Plus, Taiwanese Baseball and Dave’s perverted palate.

]]>
+ + Ah, the sounds of spring. Birds chirping, dogs grilling, and the triumphant return of Kevys Country Breakfast. Join us for an all access guided tour as the Princes of Pod prepare to reclaim their crown of audio royalty. Plus, Taiwanese Baseball and Dave’s perverted palate.

]]> +
+ + Ah, the sounds of spring. Birds chirping, dogs grilling, and the triumphant return of Kevys Country Breakfast. Join us for an all access guided tour as the Princes of Pod prepare to reclaim their crown of audio royalty. Plus, Taiwanese Baseball and Dave’s perverted palate.

]]> +
@@ -68,6 +72,7 @@ full + Episode #4: Oh Barry, Where Art Thou? Episode #4: Oh Barry, Where Art Thou?