refactor(manga): Chapter entité DDD de Manga + AggregateRoot

- Ajoute AggregateRoot dans Shared (domain events + pull pattern)
- Manga extends AggregateRoot, devient vrai aggregate root DDD
- Chapter passe de readonly à entité mutable avec MangaId VO
- Manga expose les méthodes domaine pour toute mutation de chapitre :
  addChapter, updateChapterTitle/Volume/Pages, hideChapter, removeChapterPages
- Supprime saveChapter/updateChapter/deleteChapter de MangaRepositoryInterface
- save(Manga) gère désormais la persistance des chapitres via pull pattern
- Tous les handlers/listeners passent par l'agrégat (plus d'accès direct)
- phparkitect autorise AggregateRoot dans les couches Domain

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2026-03-09 19:15:11 +01:00
parent a4b3d8a5f1
commit 2c051351a8
18 changed files with 226 additions and 255 deletions

View File

@@ -6,8 +6,6 @@ use App\Domain\Manga\Application\Command\ImportChapter;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
use App\Domain\Manga\Domain\Exception\ChapterNotFoundException;
use App\Domain\Manga\Domain\Model\Chapter;
use App\Domain\Manga\Domain\Model\ValueObject\ChapterId;
use App\Domain\Shared\Domain\Contract\MangaPathManagerInterface;
readonly class ImportChapterHandler
@@ -43,20 +41,9 @@ readonly class ImportChapterHandler
// 4. Save the CBZ file to storage using the path manager
$cbzPath = $this->saveCbzFile($command, $manga, $existingChapter);
// 5. Update existing chapter with new path
// Note: pagesDirectory holds CBZ path during transition; Phase 3 will store individual images
$updatedChapter = new Chapter(
id: new ChapterId($existingChapter->getId()),
mangaId: $existingChapter->getMangaId(),
number: $existingChapter->getNumber(),
title: $existingChapter->getTitle(),
volume: $existingChapter->getVolume(),
isVisible: $existingChapter->isVisible(),
pagesDirectory: $cbzPath,
pageCount: $existingChapter->getPageCount(),
createdAt: $existingChapter->getCreatedAt()
);
$this->mangaRepository->updateChapter($updatedChapter);
// 5. Update existing chapter with new path through the aggregate
$manga->updateChapterPages($existingChapter, $cbzPath, $existingChapter->getPageCount());
$this->mangaRepository->save($manga);
}
private function isValidCbzFile(string $fileBinary): bool
@@ -66,7 +53,7 @@ readonly class ImportChapterHandler
return strpos($fileBinary, $zipMagicNumber) === 0;
}
private function saveCbzFile(ImportChapter $command, \App\Domain\Manga\Domain\Model\Manga $manga, Chapter $chapter): string
private function saveCbzFile(ImportChapter $command, \App\Domain\Manga\Domain\Model\Manga $manga, \App\Domain\Manga\Domain\Model\Chapter $chapter): string
{
$volumeNumber = $chapter->getVolume() ?? 0;
$cbzPath = $this->pathManager->buildChapterCbzPath(