More MVC style
This commit is contained in:
51
src/Repositories/PostRepositoryInterface.php
Normal file
51
src/Repositories/PostRepositoryInterface.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
/**
|
||||
* Interface décrivant les opérations sur les posts.
|
||||
*/
|
||||
interface PostRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Retourne tous les posts triés par id descendant.
|
||||
*
|
||||
* @return array<int, array{id:int, title:string, content:string}>
|
||||
*/
|
||||
public function allDesc(): array;
|
||||
|
||||
/**
|
||||
* Trouve un post par son id.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array{id:int, title:string, content:string}|null
|
||||
*/
|
||||
public function find(int $id): ?array;
|
||||
|
||||
/**
|
||||
* Crée un post.
|
||||
*
|
||||
* @param array{title:string,content:string} $data
|
||||
* @return int id inséré
|
||||
*/
|
||||
public function create(array $data): int;
|
||||
|
||||
/**
|
||||
* Met à jour un post.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array{title:string,content:string} $data
|
||||
* @return void
|
||||
*/
|
||||
public function update(int $id, array $data): void;
|
||||
|
||||
/**
|
||||
* Supprime un post.
|
||||
*
|
||||
* @param int $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete(int $id): void;
|
||||
}
|
||||
@@ -10,7 +10,7 @@ use Medoo\Medoo;
|
||||
* Repository pour "post" basé sur Medoo.
|
||||
* Retourne et consomme des tableaux associatifs.
|
||||
*/
|
||||
class PostRepositoryMedoo
|
||||
class PostRepositoryMedoo implements PostRepositoryInterface
|
||||
{
|
||||
private Medoo $db;
|
||||
|
||||
@@ -20,7 +20,7 @@ class PostRepositoryMedoo
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{id:int, title:string, content:string}>
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function allDesc(): array
|
||||
{
|
||||
@@ -35,7 +35,7 @@ class PostRepositoryMedoo
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{id:int, title:string, content:string}|null
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function find(int $id): ?array
|
||||
{
|
||||
@@ -53,8 +53,7 @@ class PostRepositoryMedoo
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{title:string,content:string} $data
|
||||
* @return int Inserted id
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function create(array $data): int
|
||||
{
|
||||
@@ -66,9 +65,7 @@ class PostRepositoryMedoo
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param array{title:string,content:string} $data
|
||||
* @return void
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function update(int $id, array $data): void
|
||||
{
|
||||
@@ -79,8 +76,7 @@ class PostRepositoryMedoo
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return void
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(int $id): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user