Article
in package
Article Entity - Business object representing an article
This entity encapsulates all article data and business logic following Domain-Driven Design principles. Properties are private to ensure data integrity and encapsulation.
Business Logic:
- getShortDescription(): Get truncated description for previews
- getFormattedDate(): Get human-readable creation date
Tags
Table of Contents
Properties
- $adminCreatorId : int|null
- $author : string
- $createdAt : string
- $description : string
- $id : int|null
- $imageUrl : string|null
- $publisherName : string
- $slug : string
- $title : string
Methods
- __construct() : mixed
- getAdminCreatorId() : int|null
- getAuthor() : string
- getCreatedAt() : string
- getDescription() : string
- getFormattedDate() : string
- Get formatted creation date for display (French format: dd/mm/YYYY)
- getFormattedDateTime() : string
- Get formatted creation date with time (French format: dd/mm/YYYY à HH:MM)
- getId() : int|null
- getImageUrl() : string|null
- getImageUrlOrPlaceholder() : string
- Get a safe image URL (returns placeholder if no image)
- getPublisherName() : string
- Get display name for "publié par X" (admin who published) Falls back to author if no publisher name (legacy articles)
- getShortDescription() : string
- Get truncated description for article previews
- getSlug() : string
- getTitle() : string
- hasImage() : bool
- Check if article has an image
- setAuthor() : void
- setDescription() : void
- setImageUrl() : void
- setSlug() : void
- setTitle() : void
Properties
$adminCreatorId
private
int|null
$adminCreatorId
= null
$author
private
string
$author
$createdAt
private
string
$createdAt
$description
private
string
$description
$id
private
int|null
$id
$imageUrl
private
string|null
$imageUrl
$publisherName
private
string
$publisherName
= ''
$slug
private
string
$slug
$title
private
string
$title
Methods
__construct()
public
__construct(int|null $id, string $title, string $slug, string $description, string|null $imageUrl, string $author, string $createdAt[, int|null $adminCreatorId = null ][, string $publisherName = '' ]) : mixed
Parameters
- $id : int|null
-
Unique identifier (null for new articles)
- $title : string
-
Article title
- $slug : string
-
SEO-friendly URL slug
- $description : string
-
Article content/description
- $imageUrl : string|null
-
Cloudinary image URL (nullable)
- $author : string
-
Author full name (legacy / fallback)
- $createdAt : string
-
Creation timestamp
- $adminCreatorId : int|null = null
-
User ID of admin/superadmin who published (nullable for legacy)
- $publisherName : string = ''
-
"Prénom Nom" of admin who published (for display "publié par X")
getAdminCreatorId()
public
getAdminCreatorId() : int|null
Return values
int|nullgetAuthor()
public
getAuthor() : string
Return values
stringgetCreatedAt()
public
getCreatedAt() : string
Return values
stringgetDescription()
public
getDescription() : string
Return values
stringgetFormattedDate()
Get formatted creation date for display (French format: dd/mm/YYYY)
public
getFormattedDate() : string
Return values
string —Formatted date string
getFormattedDateTime()
Get formatted creation date with time (French format: dd/mm/YYYY à HH:MM)
public
getFormattedDateTime() : string
Return values
string —Formatted datetime string
getId()
public
getId() : int|null
Return values
int|nullgetImageUrl()
public
getImageUrl() : string|null
Return values
string|nullgetImageUrlOrPlaceholder()
Get a safe image URL (returns placeholder if no image)
public
getImageUrlOrPlaceholder([string $placeholder = '/assets/img/default-article.jpg' ]) : string
Parameters
- $placeholder : string = '/assets/img/default-article.jpg'
-
Default placeholder URL
Return values
string —Image URL or placeholder
getPublisherName()
Get display name for "publié par X" (admin who published) Falls back to author if no publisher name (legacy articles)
public
getPublisherName() : string
Return values
stringgetShortDescription()
Get truncated description for article previews
public
getShortDescription([int $limit = 150 ]) : string
Returns a shortened version of the description with ellipsis if it exceeds the specified limit. Useful for article listings and previews where full content is not needed.
Parameters
- $limit : int = 150
-
Maximum character length (default: 150)
Return values
string —Truncated description with ellipsis if needed
getSlug()
public
getSlug() : string
Return values
stringgetTitle()
public
getTitle() : string
Return values
stringhasImage()
Check if article has an image
public
hasImage() : bool
Return values
bool —True if article has an image URL
setAuthor()
public
setAuthor(string $author) : void
Parameters
- $author : string
setDescription()
public
setDescription(string $description) : void
Parameters
- $description : string
setImageUrl()
public
setImageUrl(string|null $imageUrl) : void
Parameters
- $imageUrl : string|null
setSlug()
public
setSlug(string $slug) : void
Parameters
- $slug : string
setTitle()
public
setTitle(string $title) : void
Parameters
- $title : string