Added:
- fix progressbar
- {slug} {chapterNumber} in Url
- activity toolbar
This commit is contained in:
34
src/Service/ChapterUrlGenerator.php
Normal file
34
src/Service/ChapterUrlGenerator.php
Normal 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.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user