Skip to main content

Overview

The base Component class in Lyger\Components provides a foundation for building reusable, view-based components with lifecycle hooks and property management.

Class: Lyger\Components\Component

Abstract base class for creating components with automatic view rendering and property binding.

Basic Component

Lifecycle Methods

mount()

Called when the component is instantiated. Override to initialize component state.
Example:

beforeRender()

Called before each render. Use for pre-render logic or data preparation.
Example:

render()

Renders the component and returns HTML string. Automatically calls beforeRender().
string
The rendered HTML output

View Management

view()

Sets the view template for the component.
string
required
View name (e.g., ‘components.button’)
Component
Returns self for method chaining
Example:

getView()

Gets the current view name.
string
The view name

renderView()

Renders the view with component properties as variables.
string
Rendered HTML
Views are loaded from resources/views/. If the view file doesn’t exist, renderInline() is called as fallback.

renderInline()

Override this to provide inline HTML when no view file exists.

getDefaultViewName()

Automatically generates a view name from the class name.
Example:

Property Management

setProperty()

Sets a component property.
string
required
Property name
mixed
required
Property value

getProperty()

Gets a component property value.
string
required
Property name
mixed
Property value or null if not set

Magic Methods

The component supports magic property access:
Example:

Method Invocation

call()

Invokes a method on the component with parameters.
string
required
Method name to call
array
Method parameters
array
Result containing ‘success’, ‘data’, ‘updates’, or ‘error’
Example:

Data Export

toArray()

Exports component data as an array.
array
Array with ‘properties’ and ‘view’ keys
Example:

refresh()

Refreshes and returns component data.
array
Fresh component data

Events

emit()

Emits an event with optional data payload.
string
required
Event name
mixed
Event data
array
Event descriptor array
Example:

Validation

validate()

Validates component properties against rules.
array
required
Validation rules
array
Custom validation messages
array
Validated data
ValidationException
Thrown when validation fails
Example:

Component Manager

Lyger\Components\ComponentManager

Manages component registration and instantiation.

register()

Registers a component class with a name.
string
required
Component name
string
required
Fully qualified class name

make()

Creates a component instance by name.
string
required
Registered component name
Component
Component instance
RuntimeException
If component is not registered

getRegistered()

Gets all registered components.
array
Array of registered component names and classes

Slot Class

Lyger\Components\Slot

Represents a content slot within a component.

LiveHandler

Lyger\Components\LiveHandler

Handles AJAX requests for live component updates.

handle()

Processes incoming AJAX requests and returns component response.
array
required
Request data containing ‘component’, ‘method’, ‘params’, ‘properties’
array
Component response with method result
Request Structure:

Complete Example

View Template Example

Tabs Example