\Omega\View ViewManager

View manager class.

The ViewManager class is responsible for managing views and rendering templates.

Summary

Methods
Properties
Constants
addPath
addEngine
render
addMacro
useMacro
No public properties found
No public constants found
No protected methods found
paths
engines
macros
No protected constants found
No private methods found
No private properties found
No private constants found

Properties

$paths

$paths : array

View path.

Type

array<int, string> — Holds an array of view paths where templates are searched for.

$engines

$engines : array

Engines engine.

Type

array<string, EngineInterface> — Holds an array of engines associated with file extensions.

$macros

$macros : array

Macros.

Type

array<string, Closure> — Holds an array of macro closures for extending functionality.

Methods

addPath()

addPath(string  $path) : $this

Add the view path.

Parameters

string $path

Holds the view path to be added-

Returns

$this —

addEngine()

addEngine(string  $extension, \Omega\View\Engine\EngineInterface  $engine) : $this

Add a engine for a specific file extension.

Parameters

string $extension

Holds the file extension (e.g., 'php', 'html').

\Omega\View\Engine\EngineInterface $engine

Holds an instance of the engine.

Returns

$this —

render()

render(string  $template, array  $data = []) : \Omega\View\View

Render a view template.

Parameters

string $template

Holds the template name (without extension).

array $data

Holds an array of data to pass to the template.

Throws

\Exception

if the specified template does not exist.

Returns

\Omega\View\View —

Return an instance of the rendered view.

addMacro()

addMacro(string  $name, \Closure  $closure) : $this

Add a custom macro for extending functionality.

Parameters

string $name

Holds the macro name.

\Closure $closure

Holds a closure that defines the macro's behavior.

Returns

$this —

useMacro()

useMacro(string  $name, mixed  ...$values) : mixed

Use a defined macro.

Parameters

string $name

Holds the name of the macro to use.

mixed $values variadic

Holds an additional values or parameters to pass to the macro.

Throws

\Exception

if the specified macro is not defined.

Returns

mixed —

Returns the result of executing the specified macro.