PHP Luminova: HTML Document Builder
Generate an HTML document and calendar using the Luminova document builder module.
The Luminova Document Builder class is a foundational helper for both Luminova\Components\Widget\Xhtml and Luminova\Components\Widget\Inputs, which extend it to inherit dynamic configuration capabilities. The Document class includes core utilities, such as a calendar method for generating HTML calendar UIs, along with other helper functions.
For full instructions on generating elements, see the XML & XHTML Documentation and Form Input Documentation.
Class Definition
- Class namespace:
Luminova\Components\Widget\Document
Constants
Defines the types of HTML document templates.
| Constant | Value | Description |
|---|---|---|
HTML5 | 1 | Represents a standard HTML5 document template. |
BOOTSTRAP5 | 2 | Represents a Bootstrap 5 document template with pre-defined styles and components. |
Properties
docTypes
List of html document types.
/**
* @var array<string, string>
*/
public static array $docTypes = [
'html5' => '<!DOCTYPE html>',
// Additional built-in declarations.
];template
The document element style to use in Luminova\Components\Widget\Xhtml class (e.g, Xhtml::HTML5, Xhtml::BOOTSTRAP5).
public static int $template = 1;encoding
Use encoding for escaping document element, contents and attributes.
public static string $encoding = 'UTF-8';xhtmlStrictTagNames
This property determines whether element tag names should be automatically converted to lowercase (in strict XHTML mode) or preserved as they were passed, which can be useful for applications using custom template elements or case-sensitive tags (such as when working with XML-like data structures).
public static bool $xhtmlStrictTagNames = true;Methods
doctype
Retrieve a <!DOCTYPE > based on the name-type.
public static function doctype(string $type = 'html5'): ?stringParameters:
| Parameter | Type | Description |
|---|---|---|
$type | string | The type of your document retrieve. |
Return:
string|null - Returns the document type declaration for the given key, or null for an unknown key.
calendar
Generates a calendar for a specified month and year, highlighting important seasonal days.
This method constructs an HTML representation of a calendar for the given month and year.It allows the specification of significant seasonal days that are highlighted in the calendar.The calendar is adjustable based on the provided timezone and allows for customization of the starting month and day of the season.
public static function calendar(
?int $year = null,
?int $month = null,
DateTimeZone|string|null $timezone = null,
array $season_days = [],
int $season_start_month = 1,
int $season_start_day = 3
): string|boolParameters:
| Parameter | Type | Description |
|---|---|---|
$year | int\|null | The year for which the calendar is generated (default: currentYear). |
$month | int\|null | The month for which the calendar is generated (default: currentMonth). |
$timezone | \DateTimeZone|string|null | The timezone to be used for date calculations (default: systemTimezone). |
$season_days | array<int, string> | An optional array of names representing significant days or events in the season. |
$season_start_month | int | The starting month of the season (1-12) (default: January). |
$season_start_day | int | The starting day of the season (1-31) (default: 3). |
Return:
string|false - Returns the generated HTML calendar as a string, or false if the calendar cannot be generated.
Throws:Luminova\Exceptions\DateTimeException Throws if invalid calendar date format is provided.
Example:
use Luminova\Components\Widget\Document;
echo Document::calendar(2024, 4, 'Africa/Lagos');The example renders an HTML table for April 2024.
attributes
Generate HTML attributes as a string and escape values while generating.
public static function attributes(array $attributes): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$attributes | array<string, string|int|float|bool|null> | Attribute names and values. Null emits a bare attribute. Booleans emit the literal strings true and false. |
Return:
string - Returns the serialized attributes, each preceded by a space, or an empty string for an empty array.