Table of Contents

FrontService

Layer: Service · Source: lib/service/FrontService.php:43 (lines 43–631)


class FrontService

FrontService — front-end content retrieval service.

Provides a unified, injectable service for retrieving published front-end content (posts, pages, topics/categories, archives, tags, galleries). Used by FrontHelper (as a delegation target) and by request handlers for content validation and rendering.

All database queries use prepared statements via Registry::get('dbc') or delegate to injected DAO instances when available. Methods mirror the legacy FrontHelper static API so that FrontHelper can delegate to this service, providing backward compatibility while centralising data access.

\

// Via Registry (typical usage)
$frontService = Registry::get('frontService');
$post = $frontService->getPublishedPost(42);

// Constructor injection (testing or DI)
$service = new FrontService($postDao, $pageDao, $topicDao, $mediaDao);
\

Docblock Metadata

Tag Value
@category Service
@author System
@license MIT
@version 1.0
@since Since Release 1.0

Inheritance

No parent, interface or trait. This is a root type.

Constants (0)

None.

Properties (6)

Visibility Type Name Default Line
private ''?PostDao'' $postDao 50
private ''?PageDao'' $pageDao 57
private ''?TopicDao'' $topicDao 64
private ''?MediaDao'' $mediaDao 71
private bool $hasSanitizer 78
private ''?Sanitize'' $sanitizer 85

Methods (13)

Visibility Method Summary Line
public __construct() Construct a new FrontService. 98
public getPublishedPost() Retrieve a published post by ID, including author and media metadata. 122
public getPublishedPage() Retrieve a published page by its slug. 178
public getPublishedTopic() Retrieve a published topic/category by its slug. 253
public getPublishedTopicById() Retrieve a published topic/category by its ID. 291
public getSimplePost() Retrieve a simple post by ID (basic fields, no archive columns). 325
public getSimpleTopic() Retrieve a simple topic/category by ID. 368
public getSimplePage() Retrieve a simple page by ID. 395
public getSimpleArchive() Retrieve archive index (all years/months with published blog posts). 437
public searchTag() Search for a tag in published blog posts. 466
public getTagLists() Retrieve a list of all unique, trimmed tags across published posts. 501
public getArchivePosts() Retrieve published posts for a specific archive month/year. 537
public getGalleries() Retrieve gallery images (media targeted as 'gallery'). 589

__construct()

public function __construct($postDao = null, $pageDao = null, $topicDao = null, $mediaDao = null)

lines 98–110 (13)

Construct a new FrontService.

Accepts optional DAO instances. Any DAO not provided will be resolved from the global Registry at construction time.

Parameter Type Default Description
$postDao (untyped) null Optional post DAO.
$pageDao (untyped) null Optional page DAO.
$topicDao (untyped) null Optional topic DAO.
$mediaDao (untyped) null Optional media DAO.

getPublishedPost()

public function getPublishedPost(int $id): ?array

lines 122–167 (46)

Retrieve a published post by ID, including author and media metadata.

Uses a prepared JOIN query via the shared database connection (Registry::get('dbc')). Falls back to PostDao when the shared connection is unavailable.

Parameter Type Default Description
$id int required The post identifier.

Returns: ?array — array|null Post data with user and media information, or null.

getPublishedPage()

public function getPublishedPage(string $slug): ?array

lines 178–242 (65)

Retrieve a published page by its slug.

Tries the PageDao first (when available), then falls back to a prepared JOIN query via the shared database connection.

Parameter Type Default Description
$slug string required The page slug.

Returns: ?array — array|null Page data with author and media information, or null.

getPublishedTopic()

public function getPublishedTopic(string $slug): ?array

lines 253–283 (31)

Retrieve a published topic/category by its slug.

Uses a direct prepared statement instead of fetching all topics and iterating (avoids O(n) scan).

Parameter Type Default Description
$slug string required The topic slug.

Returns: ?array — array|null Topic data (ID, topic_title, topic_slug) or null.

getPublishedTopicById()

public function getPublishedTopicById(int $id): ?array

lines 291–315 (25)

Retrieve a published topic/category by its ID.

Parameter Type Default Description
$id int required The topic identifier.

Returns: ?array — array|null Topic data (ID, topic_title, topic_slug) or null.

getSimplePost()

public function getSimplePost($id): ?array

lines 325–358 (34)

Retrieve a simple post by ID (basic fields, no archive columns).

Legacy method matching FrontHelper::grabSimpleFrontPost().

Parameter Type Default Description
$id (untyped) required The post identifier.

Returns: ?array — array|null Post data or null.

getSimpleTopic()

public function getSimpleTopic($id): ?array

lines 368–385 (18)

Retrieve a simple topic/category by ID.

Legacy method matching FrontHelper::grabSimpleFrontTopic().

Parameter Type Default Description
$id (untyped) required The topic identifier.

Returns: ?array — array|null Topic data (ID, topic_title, topic_slug) or null.

getSimplePage()

public function getSimplePage($id): ?array

lines 395–428 (34)

Retrieve a simple page by ID.

Legacy method matching FrontHelper::grabSimpleFrontPage().

Parameter Type Default Description
$id (untyped) required The page identifier.

Returns: ?array — array|null Page data or null.

getSimpleArchive()

public function getSimpleArchive(): array

lines 437–456 (20)

Retrieve archive index (all years/months with published blog posts).

Legacy method matching FrontHelper::grabSimpleFrontArchive().

Takes no parameters.

Returns: array — array List of archive rows with year_archive and month_archive.

searchTag()

public function searchTag(string $tag): array

lines 466–494 (29)

Search for a tag in published blog posts.

Uses a LIKE query against the post_tags column.

Parameter Type Default Description
$tag string required The tag keyword to search for.

Returns: array — array Matching post data, or an empty array when not found.

getTagLists()

public function getTagLists(): array

lines 501–527 (27)

Retrieve a list of all unique, trimmed tags across published posts.

Takes no parameters.

Returns: array — array List of unique tag strings.

getArchivePosts()

public function getArchivePosts(array $values): ?array

lines 537–577 (41)

Retrieve published posts for a specific archive month/year.

Legacy method matching FrontHelper::grabPreparedFrontArchive().

Parameter Type Default Description
$values array required Associative array with 'month' and 'year' keys.

Returns: ?array — array|null Post data for the archive month, or null.

getGalleries()

public function getGalleries(int $start, int $limit): ?array

lines 589–630 (42)

Retrieve gallery images (media targeted as 'gallery').

Returns the last result from the result set, preserving the original FrontHelper::grabPreparedFrontGalleries() behaviour.

Parameter Type Default Description
$start int required Offset for pagination.
$limit int required Maximum number of rows to query.

Returns: ?array — array|null Single gallery row with media_filename, media_caption, media_id; or null.

Imports


This page is generated from source by 'tools/gendoc'. Edits will be overwritten.