refactor(bookmarks): remove factory chain, interfaces, and duplicated sort logic

Remove BookmarkRepositoryFactory, BookmarkServicesFactory, and all 3
repository interfaces — single-consumer abstractions with no
polymorphism. Simplify container registrar to wire directly. Extract
duplicated updateSortOrders() (60 identical lines in two repos) into
SortOrderTrait. Consolidate icon labels from template into
BookmarkService::allowedGroupIconLabels() single source of truth.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 12:10:05 +01:00
parent e746a2e874
commit 8f6c9951c1
13 changed files with 146 additions and 298 deletions

View File

@@ -1,32 +0,0 @@
<?php
namespace MintyPHP\Module\Bookmarks\Service;
use MintyPHP\Module\Bookmarks\Repository\BookmarkGroupRepository;
use MintyPHP\Module\Bookmarks\Repository\BookmarkGroupRepositoryInterface;
use MintyPHP\Module\Bookmarks\Repository\BookmarkNavigationRepository;
use MintyPHP\Module\Bookmarks\Repository\BookmarkNavigationRepositoryInterface;
use MintyPHP\Module\Bookmarks\Repository\BookmarkRepository;
use MintyPHP\Module\Bookmarks\Repository\BookmarkRepositoryInterface;
class BookmarkRepositoryFactory
{
private ?BookmarkRepository $bookmarkRepository = null;
private ?BookmarkGroupRepository $groupRepository = null;
private ?BookmarkNavigationRepository $navigationRepository = null;
public function createBookmarkRepository(): BookmarkRepositoryInterface
{
return $this->bookmarkRepository ??= new BookmarkRepository();
}
public function createBookmarkGroupRepository(): BookmarkGroupRepositoryInterface
{
return $this->groupRepository ??= new BookmarkGroupRepository();
}
public function createBookmarkNavigationRepository(): BookmarkNavigationRepositoryInterface
{
return $this->navigationRepository ??= new BookmarkNavigationRepository();
}
}

View File

@@ -2,9 +2,9 @@
namespace MintyPHP\Module\Bookmarks\Service;
use MintyPHP\Module\Bookmarks\Repository\BookmarkGroupRepositoryInterface;
use MintyPHP\Module\Bookmarks\Repository\BookmarkNavigationRepositoryInterface;
use MintyPHP\Module\Bookmarks\Repository\BookmarkRepositoryInterface;
use MintyPHP\Module\Bookmarks\Repository\BookmarkGroupRepository;
use MintyPHP\Module\Bookmarks\Repository\BookmarkNavigationRepository;
use MintyPHP\Module\Bookmarks\Repository\BookmarkRepository;
use MintyPHP\Module\Bookmarks\Support\BookmarkUrlNormalizer;
class BookmarkService
@@ -23,9 +23,9 @@ class BookmarkService
];
public function __construct(
private readonly BookmarkRepositoryInterface $bookmarkRepository,
private readonly BookmarkGroupRepositoryInterface $groupRepository,
private readonly BookmarkNavigationRepositoryInterface $navigationRepository
private readonly BookmarkRepository $bookmarkRepository,
private readonly BookmarkGroupRepository $groupRepository,
private readonly BookmarkNavigationRepository $navigationRepository
) {
}
@@ -35,6 +35,33 @@ class BookmarkService
return self::ALLOWED_GROUP_ICONS;
}
/** @return array<string, string> icon class => translated label */
public static function allowedGroupIconLabels(): array
{
return [
'bi-house' => t('Icon: Home'),
'bi-people' => t('Icon: People'),
'bi-person' => t('Icon: Person'),
'bi-folder' => t('Icon: Folder'),
'bi-file-text' => t('Icon: Document'),
'bi-gear' => t('Icon: Settings'),
'bi-shield-lock' => t('Icon: Security'),
'bi-bar-chart' => t('Icon: Chart'),
'bi-envelope' => t('Icon: Mail'),
'bi-calendar' => t('Icon: Calendar'),
'bi-clock' => t('Icon: Clock'),
'bi-star' => t('Icon: Star'),
'bi-heart' => t('Icon: Heart'),
'bi-flag' => t('Icon: Flag'),
'bi-bookmark' => t('Icon: Bookmark'),
'bi-pin-map' => t('Icon: Location'),
'bi-lightning' => t('Icon: Lightning'),
'bi-database' => t('Icon: Database'),
'bi-globe' => t('Icon: Globe'),
'bi-code-slash' => t('Icon: Code'),
];
}
/**
* @return array{groups: list<array<string, mixed>>, ungrouped: list<array<string, mixed>>}
*/

View File

@@ -1,22 +0,0 @@
<?php
namespace MintyPHP\Module\Bookmarks\Service;
class BookmarkServicesFactory
{
private ?BookmarkService $bookmarkService = null;
public function __construct(
private readonly BookmarkRepositoryFactory $bookmarkRepositoryFactory
) {
}
public function createBookmarkService(): BookmarkService
{
return $this->bookmarkService ??= new BookmarkService(
$this->bookmarkRepositoryFactory->createBookmarkRepository(),
$this->bookmarkRepositoryFactory->createBookmarkGroupRepository(),
$this->bookmarkRepositoryFactory->createBookmarkNavigationRepository()
);
}
}