Luminova Framework

PHP Luminova: Base Document Builder Helper Class

Last updated: 2024-11-04 20:24:19

Generate an HTML document and calendar using the Luminova document builder module.

The Luminova Document Builder class is a foundational helper for both \Luminova\Builder\XHTML and \Luminova\Builder\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\Builder\Document

Constants

Defines the types of HTML document templates.

ConstantValueDescription
HTML51Represents a standard HTML5 document template.
BOOTSTRAP52Represents a Bootstrap 5 document template with pre-defined styles and components.

Properties

docTypes

List of html document types.

public static array<string,string> $docTypes = [
    'html5' => '<!DOCTYPE html>',
    //...
]

template

The document element style to use in Luminova\Builder\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 doctype(string $type = 'html5'): ?string

Parameters:

ParameterTypeDescription
$typestringThe type of your document retrieve.

Return Value:

string|null - Returns content doctype based on passed type.


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 calendar( 
    ?string $year = null, 
    ?string $month = null,
    DateTimeZone|string|null $timezone = null,
    array $season_days = [],
    int $season_start_month = 1,
    int $season_start_day = 3
): string|bool

Parameters:

ParameterTypeDescription
$yearstring|nullThe year for which the calendar is generated (default: currentYear).
$monthstring|nullThe month for which the calendar is generated (default: currentMonth).
$timezone\DateTimeZone|string|nullThe timezone to be used for date calculations (default: systemTimezone).
$season_daysarray<int,string>An optional array of names representing significant days or events in the season..
$season_start_monthintThe starting month of the season (1-12) (default: January).
$season_start_dayintThe starting day of the season (1-31) (default: March).

Return Value:

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:

<?php
use Luminova\Builder\Document;

echo Document::calendar(2024, 04, `Africa/Lagos`);

Output:

Calender Example


attributes

Generate HTML attributes as a string and escape values while generating.

public static attributes(array<string,string|int|float|bool> $attributes): string

Parameters:

ParameterTypeDescription
$attributesarray<string,string|int|float|bool>An array of attributes as key-value pairs.

Return Value:

string|null - Return the attributes as a string.


esc

Escapes input for safe output in HTML, including handling numeric values directly.

public static esc(string|int|float $value): string

Parameters:

ParameterTypeDescription
$valuestring|int|floatThe value to be escaped..

Return Value:

string - Return the safely escaped string or numeric value.


getAttrType

Escape and retrieve attribute value type.

protected static getAttrType(mixed $value): string

Parameters:

ParameterTypeDescription
$valuemixedThe value of the attribute.

Return Value:

string - Return the safely escaped string or numeric value.