This commit is contained in:
julien
2026-03-09 02:11:53 +01:00
parent 2546ab9cb9
commit 6e5119348e
2 changed files with 23 additions and 4 deletions

View File

@@ -36,8 +36,9 @@ $medooOptions = [
'charset' => 'utf8',
];
// Certaines variantes/versions de Medoo s'attendent à 'database_name'.
// Dupliquer la valeur pour éviter le warning.
// Certaines variantes/versions de Medoo (selon l'installation/composer.lock)
// peuvent émettre un warning en cherchant 'database_name'.
// Dupliquer la valeur pour éviter le warning sans changer le comportement.
if (!isset($medooOptions['database_name'])) {
$medooOptions['database_name'] = $medooOptions['database_file'];
}

View File

@@ -19,15 +19,33 @@ class PostRepositoryMedoo
$this->db = $db;
}
/**
* @return array<int, array{id:int, title:string, content:string}>
*/
public function allDesc(): array
{
return $this->db->select('post', ['id', 'title', 'content'], ['ORDER' => ['id' => 'DESC']]);
$rows = $this->db->select('post', ['id', 'title', 'content'], ['ORDER' => ['id' => 'DESC']]);
return is_array($rows) ? $rows : [];
}
/**
* @return array{id:int, title:string, content:string}|null
*/
public function find(int $id): ?array
{
$row = $this->db->get('post', ['id', 'title', 'content'], ['id' => $id]);
return $row === null ? null : $row;
// Medoo peut retourner false ou empty si rien trouvé — normaliser en null.
if (empty($row) || $row === false) {
return null;
}
// Forcer types et clés attendues
return [
'id' => (int)($row['id'] ?? 0),
'title' => (string)($row['title'] ?? ''),
'content' => (string)($row['content'] ?? ''),
];
}
public function create(array $data): int