TemplateEngine
in package
implements
TemplateEngineInterface
Uses
Cacheable
Table of Contents
Interfaces
Properties
- $cachePrefix : string
- The cache prefix to use for caching.
- $cacheTtl : int
- The cache ttl to use for caching.
- $blocks : array<string|int, mixed>
- $cache_enabled : bool
- $cacheInstance : PioniaCache|null
- The cache instance to use for caching.
Methods
- cache() : bool|mixed
- Caches the value if the value is not null.
- ClearByKeys() : bool
- Clear the cache.
- clearCache() : void
- Clear the cached files
- compileEscapedEchos() : array<string|int, mixed>|string|null
- deleteCache() : bool
- Delete the cache for the key.
- getCache() : mixed
- getCacheInstance() : PioniaCache|null
- hasCache() : bool
- Check if the cache has the key.
- parse() : string
- Parse the template file and return the content as string
- setCache() : bool
- setCacheInstance() : void
- Set the cache instance to use for caching.
- updateCache() : void
- view() : void
- Render a template file
- cached() : string
- cachePath() : string
- cleanCacheKey() : string
- compileBlock() : mixed
- compileCode() : array<string|int, mixed>|string|null
- compileEchos() : array<string|int, mixed>|string|null
- compilePHP() : array<string|int, mixed>|string|null
- compileYield() : array<string|int, mixed>|string|null
- getKeyName() : string
- Converts the key to snake case and appends the current class prefix if it does not exist.
- includeFiles() : array<string|int, mixed>|string|null
- logger() : LoggerInterface|null
Properties
$cachePrefix
The cache prefix to use for caching.
public
string
$cachePrefix
= __CLASS__
$cacheTtl
The cache ttl to use for caching.
public
int
$cacheTtl
= 60
Defaults to 60 seconds.
$blocks
private
array<string|int, mixed>
$blocks
= []
$cache_enabled
private
bool
$cache_enabled
= FALSE
$cacheInstance
The cache instance to use for caching.
private
PioniaCache|null
$cacheInstance
= null
Methods
cache()
Caches the value if the value is not null.
public
cache(string $key[, mixed $value = null ][, mixed $ttl = null ][, bool|null $exact = false ]) : bool|mixed
Parameters
- $key : string
-
The key to cache
- $value : mixed = null
-
The value to cache
- $ttl : mixed = null
-
The time to live for the cache
- $exact : bool|null = false
-
If passed, the key won't be parsed at all, it will be cached as is.
Return values
bool|mixedClearByKeys()
Clear the cache.
public
ClearByKeys(array<string|int, mixed> $keys[, bool|null $exact = false ]) : bool
Parameters
- $keys : array<string|int, mixed>
-
The keys to clear
- $exact : bool|null = false
-
If passed, the keys won't be parsed at all
Return values
boolclearCache()
Clear the cached files
public
static clearCache() : void
compileEscapedEchos()
public
static compileEscapedEchos(mixed $code) : array<string|int, mixed>|string|null
Parameters
- $code : mixed
Return values
array<string|int, mixed>|string|nulldeleteCache()
Delete the cache for the key.
public
deleteCache(string $key[, bool $exact = false ]) : bool
Parameters
- $key : string
-
The key to delete
- $exact : bool = false
-
If passed, the key won't be parsed at all
Return values
boolgetCache()
public
getCache( $key[, bool|null $exact = false ]) : mixed
Parameters
getCacheInstance()
public
getCacheInstance() : PioniaCache|null
Return values
PioniaCache|nullhasCache()
Check if the cache has the key.
public
hasCache( $key[, bool|null $exact = false ]) : bool
Will not throw an exception if the key is not set or the cache is not activated.
Parameters
Return values
boolparse()
Parse the template file and return the content as string
public
parse(mixed $file[, mixed $data = array() ]) : string
Parameters
- $file : mixed
- $data : mixed = array()
Return values
stringsetCache()
public
setCache(string $key, mixed $value[, mixed $ttl = null ][, bool|null $exact = false ]) : bool
Parameters
- $key : string
- $value : mixed
- $ttl : mixed = null
- $exact : bool|null = false
Return values
boolsetCacheInstance()
Set the cache instance to use for caching.
public
setCacheInstance(PioniaCache|null $cache) : void
Parameters
- $cache : PioniaCache|null
updateCache()
public
updateCache(mixed $key, mixed $newValue[, mixed $exact = false ][, int|null $ttl = null ]) : void
Parameters
- $key : mixed
- $newValue : mixed
- $exact : mixed = false
- $ttl : int|null = null
view()
Render a template file
public
view(mixed $file[, mixed $data = array() ]) : void
Parameters
- $file : mixed
- $data : mixed = array()
cached()
private
cached(mixed $file) : string
Parameters
- $file : mixed
Return values
stringcachePath()
private
cachePath() : string
Return values
stringcleanCacheKey()
private
cleanCacheKey(string $key) : string
Parameters
- $key : string
Return values
stringcompileBlock()
private
compileBlock(mixed $code) : mixed
Parameters
- $code : mixed
compileCode()
private
compileCode(mixed $code) : array<string|int, mixed>|string|null
Parameters
- $code : mixed
Return values
array<string|int, mixed>|string|nullcompileEchos()
private
compileEchos(mixed $code) : array<string|int, mixed>|string|null
Parameters
- $code : mixed
Return values
array<string|int, mixed>|string|nullcompilePHP()
private
compilePHP(mixed $code) : array<string|int, mixed>|string|null
Parameters
- $code : mixed
Return values
array<string|int, mixed>|string|nullcompileYield()
private
compileYield(mixed $code) : array<string|int, mixed>|string|null
Parameters
- $code : mixed
Return values
array<string|int, mixed>|string|nullgetKeyName()
Converts the key to snake case and appends the current class prefix if it does not exist.
private
getKeyName(string $key) : string
Parameters
- $key : string
Return values
stringincludeFiles()
private
includeFiles(mixed $file) : array<string|int, mixed>|string|null
Parameters
- $file : mixed
Return values
array<string|int, mixed>|string|nulllogger()
private
logger() : LoggerInterface|null