class ViewService (View source)

Provide general view-related functionality.

Methods

__construct(array $config, ViewEngineInterface $engine, HandlerFactory $handler_factory)

Constructor.

array
getGlobals()

Get global variables.

void
addGlobal(string $key, mixed $value)

Set a global variable.

void
addGlobals(array $globals)

Set an array of global variables.

getComposersForView(string $view)

Get view composer.

void
addComposer(string|string[] $views, string|Closure $composer)

Add view composer.

void
compose(ViewInterface $view)

Composes a view instance with contexts in the following order: Global, Composers, Local.

boolean
exists(string $view)

Check if a view exists.

string
canonical(string $view)

Return a canonical string representation of the view name.

make(string|string[] $views)

Create a view instance from the first view name that exists.

void
triggerPartialHooks(string $name)

Trigger core hooks for a partial, if any.

void
render(string|string[] $views, array $context = [])

Render a view.

Details

__construct(array $config, ViewEngineInterface $engine, HandlerFactory $handler_factory)

Constructor.

Parameters

array $config mixed> $config
ViewEngineInterface $engine
HandlerFactory $handler_factory

array getGlobals()

Get global variables.

Return Value

array

void addGlobal(string $key, mixed $value)

Set a global variable.

Parameters

string $key
mixed $value

Return Value

void

void addGlobals(array $globals)

Set an array of global variables.

Parameters

array $globals

Return Value

void

Handler[] getComposersForView(string $view)

Get view composer.

Parameters

string $view

Return Value

Handler[]

void addComposer(string|string[] $views, string|Closure $composer)

Add view composer.

Parameters

string|string[] $views
string|Closure $composer

Return Value

void

void compose(ViewInterface $view)

Composes a view instance with contexts in the following order: Global, Composers, Local.

Parameters

ViewInterface $view

Return Value

void

boolean exists(string $view)

Check if a view exists.

Parameters

string $view

Return Value

boolean

string canonical(string $view)

Return a canonical string representation of the view name.

Parameters

string $view

Return Value

string

ViewInterface make(string|string[] $views)

Create a view instance from the first view name that exists.

Parameters

string|string[] $views

Return Value

ViewInterface

void triggerPartialHooks(string $name)

Trigger core hooks for a partial, if any.

Parameters

string $name

Return Value

void

void render(string|string[] $views, array $context = [])

Render a view.

Parameters

string|string[] $views
array $context mixed> $context

Return Value

void