Documentation

CComponent
in package

CComponent Class

Handles component-specific logic:

  • Loading component HTML templates
  • Resolving component file paths (plugins vs core)
  • Rendering components using CHtmlRender
  • Loading associated CSS and JS files
  • Returning structured output (HTML + CSS + JS)

Component Structure: views/{view_folder}/components/{type}/

  • {type}.html (template)
  • css/{type}.css (optional styles)
  • js/{type}.js (optional scripts)
Tags
category

Template

author

Tufano Pasquale

license

Apache 2.0

link
https://dressapi.com

Table of Contents

Properties

$component_resolver  : callable|null
Component file resolver callback
$logger  : ILogger|null
Logger instance
$renderer  : CHtmlRender
Template renderer instance

Methods

__construct()  : void
Constructor
RegisterModifier()  : void
Register Modifier
RenderComponent()  : array<string|int, mixed>
Render Component
SetComponentResolver()  : void
Set Component Resolver
SetIncludeResolver()  : void
Set Include Resolver
ExtractSection()  : string|null
Extract Section
IsIndexedArray()  : bool
Check if Array is Indexed
Log()  : void
Log Message
PostProcessHtml()  : string
Post-Process HTML
ProcessCardinalityTags()  : array<string|int, mixed>
Process Cardinality Tags
ProcessDefaultTags()  : string
Process Default Tags
ProcessDropdownItems()  : string
Process Dropdown Items
ProcessNestedConditionals()  : string
Process Nested Conditionals
ProcessRepeatAttributeTags()  : string
Process Repeat Attribute Tags
ProcessRepeatTags()  : string
Process Repeat Tags
UpdateVariableReferences()  : string
Update Variable References

Properties

$component_resolver

Component file resolver callback

private callable|null $component_resolver

Methods

__construct()

Constructor

public __construct([callable|null $translator = null ][, ILogger|null $logger = null ][, callable|null $debugger = null ]) : void

Initializes the component renderer with CHtmlRender as the template engine.

Parameters
$translator : callable|null = null

Optional translation function

$logger : ILogger|null = null

Optional logger instance

$debugger : callable|null = null

Optional debug printer function

RegisterModifier()

Register Modifier

public RegisterModifier(string $name, callable $callback) : void

Delegates modifier registration to CHtmlRender. Allows adding custom filters for use in component templates.

Parameters
$name : string

Modifier name

$callback : callable

Modifier function

RenderComponent()

Render Component

public RenderComponent(string $component_type, array<string|int, mixed> $data, array<string|int, mixed> $attributes[, string $module = 'base' ]) : array<string|int, mixed>

Main method to render a component with its associated assets.

Process:

  1. Resolve component HTML template file
  2. Load and clean template content
  3. Render using CHtmlRender (handles [if], [foreach], {}} placeholders)
  4. Load associated CSS file (if exists)
  5. Load associated JS file (if exists)
  6. Return structured array with HTML, CSS, JS
Parameters
$component_type : string

Component type name (e.g., 'dropdown')

$data : array<string|int, mixed>

Data context for rendering

$attributes : array<string|int, mixed>

Special attributes (e.g., component_id)

$module : string = 'base'

Module name (optional)

Return values
array<string|int, mixed> —

Associative array ['html' => string, 'css' => string, 'js' => string]

SetComponentResolver()

Set Component Resolver

public SetComponentResolver(callable $resolver) : void

Sets the callback function used to resolve component file paths. The resolver receives (component_type, file_type, module) and returns full path.

Parameters
$resolver : callable

The resolver function

SetIncludeResolver()

Set Include Resolver

public SetIncludeResolver(callable $resolver) : void

Delegates include resolver configuration to CHtmlRender. Used for [include] tags within component templates.

Parameters
$resolver : callable

The include resolver function

ExtractSection()

Extract Section

private ExtractSection(string $template, string $tag) : string|null

Extracts content between [tag] and [/tag] markers.

Parameters
$template : string

Template content

$tag : string

Tag name (single, multiple, empty)

Return values
string|null —

Extracted content or null if not found

IsIndexedArray()

Check if Array is Indexed

private IsIndexedArray(array<string|int, mixed> $array) : bool

Determines if an array is indexed (0, 1, 2...) rather than associative.

Parameters
$array : array<string|int, mixed>

Array to check

Return values
bool —

True if indexed, false if associative

Log()

Log Message

private Log(string $message, string $level) : void

Logs a message using the logger instance if available.

Parameters
$message : string

Log message

$level : string

Log level (DEBUG, WARNING, ERROR)

PostProcessHtml()

Post-Process HTML

private PostProcessHtml(string $html) : string

Performs post-processing on rendered HTML to handle Bootstrap-specific attributes.

Parameters
$html : string

Rendered HTML

Return values
string —

Processed HTML

ProcessCardinalityTags()

Process Cardinality Tags

private ProcessCardinalityTags(string $template_content, array<string|int, mixed> $data) : array<string|int, mixed>

Processes [single], [multiple], and [empty] tags in component templates. Selects the appropriate section based on data cardinality and converts [repeat] tags to [foreach] loops for CHtmlRender.

Parameters
$template_content : string

Template content with cardinality tags

$data : array<string|int, mixed>

Data context

Return values
array<string|int, mixed> —

Array with 'template' and 'data' keys

ProcessDefaultTags()

Process Default Tags

private ProcessDefaultTags(string $template) : string

Converts [default]...[/default] tags to [else] for use with [if-exists]. The [default] tag represents the else clause of a conditional.

Parameters
$template : string

Template content

Return values
string —

Template with [else] tags

ProcessDropdownItems()

Process Dropdown Items

private ProcessDropdownItems(string $html) : string

Converts custom tags to proper Bootstrap Italia dropdown HTML. Uses link-list structure with list-item class for proper hover effects.

Parameters
$html : string

HTML with dropdown-item tags

Return values
string —

Processed HTML

ProcessNestedConditionals()

Process Nested Conditionals

private ProcessNestedConditionals(string $template, string $tag_type, array<string|int, mixed> $item) : string

Process nested [if-exists(item::)] or [if-not-exists(item::)] conditionals by matching opening and closing tags correctly.

Parameters
$template : string

Template content

$tag_type : string

'if-exists' or 'if-not-exists'

$item : array<string|int, mixed>

Current iteration item data

Return values
string —

Processed template content

ProcessRepeatAttributeTags()

Process Repeat Attribute Tags

private ProcessRepeatAttributeTags(string $template) : string

Processes [repeat(attr)] and [repeat attribute="attr"] tags outside of cardinality blocks. Supports both shorthand and legacy syntax for backward compatibility. For nested repeats, use explicit closing: [repeat(outer)]...[repeat(inner)]...[/repeat(inner)]...[/repeat(outer)]

Parameters
$template : string

Template content

Return values
string —

Template with repeat tags converted to foreach

ProcessRepeatTags()

Process Repeat Tags

private ProcessRepeatTags(string $template, array<string|int, mixed> $data_array) : string

Converts [repeat] tags to [foreach] loops for CHtmlRender. Handles nested repeats with attribute specifications.

Also updates variable references to use the foreach item variable.

Parameters
$template : string

Template section content

$data_array : array<string|int, mixed>

Array of data items

Return values
string —

Template with [foreach] loops

UpdateVariableReferences()

Update Variable References

private UpdateVariableReferences(string $content, string $item_name) : string

Updates variable references in template content to use the foreach item variable. Converts {{varname}} to {{item::varname}}.

Parameters
$content : string

Template content

$item_name : string

Name of the foreach item variable

Return values
string —

Updated template content


        
On this page

Search results