SlaxWeb Framework
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SlaxWeb\View\AbstractLoader Class Reference
Inheritance diagram for SlaxWeb\View\AbstractLoader:
Inheritance graph
[legend]

Public Member Functions

 __construct (Response $response, Logger $logger)
 
 setTemplateExt (string $tplExt)
 
 setTemplate (string $template)
 
 setTemplateDir (string $templateDir)
 
 render (array $data=[], int $return=self::TPL_OUTPUT, int $cacheData=self::TPL_CACHE_VARS)
 

Public Attributes

const TPL_CACHE_VARS = 100
 
const TPL_USE_VARS_ONLY = 101
 
const TPL_NO_CACHE_VARS = 102
 
const TPL_RETURN = 200
 
const TPL_OUTPUT = 201
 

Protected Member Functions

 combineData (array $data, int $cacheData)
 
 load (string $template, array $data)
 

Protected Attributes

 $response = null
 
 $logger = null
 
 $tplExt = ""
 
 $template = ""
 
 $templateDir = ""
 
 $cachedData = []
 

Constructor & Destructor Documentation

SlaxWeb\View\AbstractLoader::__construct ( Response  $response,
Logger  $logger 
)

Class constructor

Assigns the dependant Response object to the class property. The View loader will automatically add template contents to as response body.

Parameters
\Symfony\Component\HttpFoundation\Response$responseResponse object
\Psr\Log\LoggerInterface$loggerPSR4 compatible Logger object

Member Function Documentation

SlaxWeb\View\AbstractLoader::combineData ( array  $data,
int  $cacheData 
)
protected

Combine data

Combines the received data and the already cached data, depending on the *$cacheData* parameter passed as the second parameter. The first parameter holds an array of data that will be combined with the cached data.

Parameters
array$dataTemplate data to be passed to the template. Default []
int$cacheDataCache template data.
Returns
array
SlaxWeb\View\AbstractLoader::load ( string  $template,
array  $data 
)
abstractprotected

Load template

Load the template file. Defined as abstract, because each loader will load its template files in a different way.

Parameters
string$templatePath to the template file
array$dataView data
Returns
string
SlaxWeb\View\AbstractLoader::render ( array  $data = [],
int  $return = self::TPL_OUTPUT,
int  $cacheData = self::TPL_CACHE_VARS 
)

Render the template

Loads the template file with the retrieved data array, and returns the rendered template. By default the template data is cached in the internal property for all future renders of that same requests. To disable the cached vars and load the template only with the currently passed in data, constant TPL_NO_CACHE_VARS has to be sent as the third parameter.

The Render method will automatically add contents of the rendered template file to the Response object as response body. If you wish to retrieve the contents back, pass in constant TPL_RETURN as the second parameter. When the rendered template is only added to the Response object, an empty string is returned.

Parameters
array$dataTemplate data to be passed to the template. Default []
int$returnOutput or return rendered template. Default self::TPL_OUTPUT
int$cacheDataCache template data. Default self::TPL_CACHE_VARS
Returns
string

SlaxWeb

SlaxWeb\View\AbstractLoader::setTemplate ( string  $template)

Set the template

Sets the template filename.

Parameters
string$templateName of the template file
Returns
self
SlaxWeb\View\AbstractLoader::setTemplateDir ( string  $templateDir)

Set the template directory

Sets the template directory name.

Parameters
string$templateDirName of the template directory
Returns
self
SlaxWeb\View\AbstractLoader::setTemplateExt ( string  $tplExt)

Set Template File Extension

Sets the template file extension to the provided value. It automatically strips the leading dot if present.

Parameters
string$tplExtTemplate File Extension
Returns
self

Member Data Documentation

const SlaxWeb\View\AbstractLoader::TPL_CACHE_VARS = 100

Template variables caching

const SlaxWeb\View\AbstractLoader::TPL_RETURN = 200

Template render output control


The documentation for this class was generated from the following file: