\Anax\ViewViewCollection

A view collection supporting Anax DI, store all views per region, render at will.

Summary

Methods
Properties
Constants
setDI()
configure()
getConfig()
getTemplateFile()
add()
addCallback()
addString()
hasContent()
render()
renderBuffered()
No public properties found
No constants found
No protected methods found
$di
$config
N/A
No private methods found
$views
N/A

Properties

$di

$di : \Anax\DI\Anax\DI\DIInterface

Type

\Anax\DI\Anax\DI\DIInterface — the DI service container.

$config

$config : array<mixed,>

Type

array<mixed,> — store the configuration in this array.

$views

$views : array<mixed,>

Type

array<mixed,> — Array for all views.

Methods

setDI()

setDI(\Anax\DI\Anax\DI\DIInterface  $di) : self

Set the service container to use

Parameters

\Anax\DI\Anax\DI\DIInterface $di

a service container

Returns

self

configure()

configure(array|string  $what) : self

Load and apply configurations.

Parameters

array|string $what

is an array with key/value config options or a file to be included which returns such an array.

Throws

\Anax\View\Anax\Configure\Exception

when template file is missing

Returns

self

getConfig()

getConfig(string  $key, string  $default = null) : mixed

Helper function for reading values from the configuration and appy default values where configuration item is missing.

Parameters

string $key

matching a key in the config array.

string $default

value returned when config item is not found.

Returns

mixed —

or null if key does not exists.

getTemplateFile()

getTemplateFile(string  $template) : string

Convert template to path to template file.

Parameters

string $template

the name of the template file to include

Throws

\Anax\View\Anax\View\Exception

when template file is missing

Returns

string —

as path to the template file

add()

add(string  $template, array  $data = array(), string  $region = "main", integer  $sort) : self

Add (create) a view to be included, pass optional data and put the view in an optional specific region (default region is "main") and pass an optional sort value where the highest value is rendered first.

The $template can be a: filename (string), callback (array with key callback set to a callable array), view array (key value array with template, data, region, sort)

Parameters

string $template

the name of the template file to include.

array $data

variables to make available to the view, default is empty.

string $region

which region to attach the view, default is "main".

integer $sort

which order to display the views.

Returns

self —

for chaining.

addCallback()

addCallback(string  $callback, array  $data = array(), string  $region = "main", integer  $sort) : $this

Add a callback to be rendered as a view.

Parameters

string $callback

function to call to get the content of the view

array $data

variables to make available to the view, default is empty

string $region

which region to attach the view

integer $sort

which order to display the views

Returns

$this

addString()

addString(string  $content, string  $region = "main", integer  $sort) : $this

Add a string as a view.

Parameters

string $content

the content

string $region

which region to attach the view

integer $sort

which order to display the views

Returns

$this

hasContent()

hasContent(string  $region) : $this

Check if a region has views to render.

Parameters

string $region

which region to check

Returns

$this

render()

render(string  $region = "main") : void

Render all views for a specific region.

Parameters

string $region

which region to use

renderBuffered()

renderBuffered(string  $region = "main") : string

Render all views for a specific region and buffer the result.

Parameters

string $region

which region to use.

Returns

string —

with the buffered results.