- fix progressbar
- {slug} {chapterNumber} in Url
- activity toolbar
This commit is contained in:
Jérémy Guillot
2024-07-07 15:25:12 +02:00
parent 54c581b229
commit 4672886a67
15 changed files with 183 additions and 59 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Service;
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
class ChapterUrlGenerator
{
private string $chapterUrlFormat;
public function __construct(string $chapterUrlFormat)
{
$this->chapterUrlFormat = $chapterUrlFormat;
$this->validateUrlFormat($chapterUrlFormat);
}
public function getChapterUrl(string $mangaTitle, float $chapterNumber): string
{
$placeholders = [
'{chapterNumber}' => $chapterNumber,
'{slug}' => $mangaTitle,
];
return str_replace(array_keys($placeholders), array_values($placeholders), $this->chapterUrlFormat);
}
private function validateUrlFormat(string $format): void
{
if (!str_contains($format, '{slug}') || !str_contains($format, '{chapterNumber}')) {
throw new InvalidArgumentException("The URL format must contain both {slug} and {chapterNumber} placeholders.");
}
}
}