0
0
Fork 0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-04-14 08:48:32 +00:00
BookStackApp_BookStack/app/Entities/Queries/EntityQueries.php
Dan Brown 8e78b4c43e
Queries: Extracted chapter repo queries to class
Updated query classes to align to interface for common aligned
operations.
Extracted repeated string-identifier-based finding from page/chapter
repos to shared higher-level entity queries.
2024-02-05 15:59:20 +00:00

43 lines
1 KiB
PHP

<?php
namespace BookStack\Entities\Queries;
use BookStack\Entities\Models\Entity;
class EntityQueries
{
public function __construct(
public BookshelfQueries $shelves,
public BookQueries $books,
public ChapterQueries $chapters,
public PageQueries $pages,
) {
}
/**
* Find an entity via an identifier string in the format:
* {type}:{id}
* Example: (book:5).
*/
public function findVisibleByStringIdentifier(string $identifier): ?Entity
{
$explodedId = explode(':', $identifier);
$entityType = $explodedId[0];
$entityId = intval($explodedId[1]);
/** @var ?ProvidesEntityQueries $queries */
$queries = match ($entityType) {
'page' => $this->pages,
'chapter' => $this->chapters,
'book' => $this->books,
'bookshelf' => $this->shelves,
default => null,
};
if (is_null($queries)) {
return null;
}
return $queries->findVisibleById($entityId);
}
}