\Phug\Renderer\AdapterFileAdapter

Renderer using files system.

Options to customize paths:

  • cache_dir directory to save the rendered files (no cache by default)
  • tmp_dir working directory (directory used to temporarily save files if no long term cache_dir is provided, sys_get_temp_dir() by default)
  • tmp_name_function function used to create temporary files (tempnam() by default)
  • up_to_date_check (true: check if templates changed since the cached file was written, false: cache can only be cleared manually)
  • keep_base_name (true: file name of the template will appear in the cached file name, false: only a hash is used in the cached file)

Summary

Methods
Properties
Constants
getRenderingFile()
__construct()
getRenderer()
captureBuffer()
render()
getOptions()
setOptions()
setOptionsRecursive()
setOptionsDefaults()
hasOption()
getOption()
setOption()
unsetOption()
addOptionNameHandlers()
resetOptions()
cache()
displayCached()
cacheFile()
cacheFileIfChanged()
cacheDirectory()
display()
locate()
No public properties found
No constants found
cacheFileContents()
reInitCompiler()
parseCliDirectoriesInput()
compileAndCache()
normalizePath()
hashPrint()
getRegistryPathChunks()
getFirstRegistryIndex()
findCachePathInRegistry()
findCachePathInRegistryFile()
execute()
registerCachedFile()
createTemporaryFile()
getCompiledFile()
$replaceFunction
$recursiveReplaceFunction
$nonDeepOptions
N/A
tryExtensionsOnFileKey()
tryExtensions()
findInRegistry()
handleOptionName()
filterTraversable()
setOptionArrays()
mergeOptionValue()
setDefaultOption()
withVariableReference()
withOptionReference()
getRawCachePath()
getCachePath()
hasExpiredImport()
getRegistryPath()
checkPathExpiration()
isCacheUpToDate()
getCacheDirectory()
$renderingFile
$renderer
$options
$optionNameHandlers
N/A

Properties

$replaceFunction

$replaceFunction : callable

Type

callable

$recursiveReplaceFunction

$recursiveReplaceFunction : callable

Type

callable

$nonDeepOptions

$nonDeepOptions : array<mixed,string>

Type

array<mixed,string>

$renderingFile

$renderingFile : string

File currently rendering.

Type

string

$renderer

$renderer : 

Type

$options

$options : \ArrayObject

Type

\ArrayObject

$optionNameHandlers

$optionNameHandlers : array

Type

array

Methods

getRenderingFile()

getRenderingFile() : string

Get file currently rendering.

Returns

string

__construct()

__construct(\Phug\Renderer  $renderer, array|\ArrayObject  $options) 

AbstractAdapter constructor.

Parameters

\Phug\Renderer $renderer

current renderer used.

array|\ArrayObject $options

options array/object to be propagated from renderer to the adapter.

getRenderer()

getRenderer() : \Phug\Renderer

Get the current linked renderer.

Returns

\Phug\Renderer

captureBuffer()

captureBuffer(callable  $display) : string

Get a callable that display/output text/HTML and return as string what those callable would have displayed.

Parameters

callable $display

function/closure that display renderer code.

Throws

\Throwable

Returns

string

render()

render(string  $php, array  $parameters) : string

Return rendered code based on capturing output of the ->display() method.

Parameters

string $php

PHP code resulting from the rendering.

array $parameters

Render local variables.

Throws

\Throwable

Returns

string

getOptions()

getOptions() 

{@inheritdoc}

setOptions()

setOptions(  $options) 

{@inheritdoc}

Parameters

$options

setOptionsRecursive()

setOptionsRecursive(  $options) 

{@inheritdoc}

Parameters

$options

setOptionsDefaults()

setOptionsDefaults(  $options = null) 

{@inheritdoc}

Parameters

$options

hasOption()

hasOption(  $name) 

{@inheritdoc}

Parameters

$name

getOption()

getOption(  $name) 

{@inheritdoc}

Parameters

$name

setOption()

setOption(  $name,   $value) 

{@inheritdoc}

Parameters

$name
$value

unsetOption()

unsetOption(  $name) 

{@inheritdoc}

Parameters

$name

addOptionNameHandlers()

addOptionNameHandlers(callable  $handler) 

Parameters

callable $handler

resetOptions()

resetOptions() 

cache()

cache(string  $path, string  $input, callable  $rendered, \Phug\Renderer\Adapter\&bool  $success = null) : string

Return the cached file path after cache optional process.

Parameters

string $path

pug file

string $input

pug input code

callable $rendered

method to compile the source into PHP

\Phug\Renderer\Adapter\&bool $success

reference to a variable to be set to true/false on success/failure

Returns

string

displayCached()

displayCached(string  $path, string  $input, callable  $rendered, array  $variables, \Phug\Renderer\Adapter\&bool  $success = null) 

Display rendered template after optional cache process.

Parameters

string $path

pug file

string $input

pug input code

callable $rendered

method to compile the source into PHP

array $variables

local variables

\Phug\Renderer\Adapter\&bool $success

reference to a variable to be set to true/false on success/failure

cacheFile()

cacheFile(string  $path) : boolean|integer

Cache a template file in the cache directory (even if the cache is up to date).

Returns the number of bytes written in the cache file or false if a failure occurred.

Parameters

string $path

pug file

Returns

boolean|integer

cacheFileIfChanged()

cacheFileIfChanged(string  $path) : boolean|integer

Cache a template file in the cache directory if the cache is obsolete.

Returns true if the cache is up to date and cache not change, else returns the number of bytes written in the cache file or false if a failure occurred.

Parameters

string $path

Returns

boolean|integer

cacheDirectory()

cacheDirectory(array<mixed,string>|string  $directory) : array

Scan a directory recursively for its views, compile them and save them into the cache directory.

Parameters

array<mixed,string>|string $directory

the directory to search pug files in it.

Throws

\Phug\RendererException

Returns

array —

count of cached files and error count

display()

display(string  $__pug_php, array  $__pug_parameters) 

Compile then render a file with given locals.

Parameters

string $__pug_php
array $__pug_parameters

locate()

locate(string  $path, array  $locations, array  $extensions) : string

Translates a given path by searching it in the passed locations and with the passed extensions.

Parameters

string $path

the file path to translate.

array $locations

the directories to search in.

array $extensions

the file extensions to search for (e.g. ['.jd', '.pug'].

Returns

string

cacheFileContents()

cacheFileContents(string  $destination, string  $output, array  $importsMap = array()) : boolean

Write the cache file with the given contents and map of imports.

Parameters

string $destination
string $output
array $importsMap

Returns

boolean

reInitCompiler()

reInitCompiler(\Phug\Renderer  $renderer, array  $events) : \Phug\CompilerInterface

Parameters

\Phug\Renderer $renderer
array $events

Throws

\Phug\RendererException

Returns

\Phug\CompilerInterface

parseCliDirectoriesInput()

parseCliDirectoriesInput(string  $directory) : array<mixed,string>

Return directories list from a directory string as it is allowed in CLI: - directory1/x/y - [directory1/x/y,directory2/z] as an array of strings.

Parameters

string $directory

Returns

array<mixed,string>

compileAndCache()

compileAndCache(\Phug\CompilerInterface  $compiler, string  $path, string  $inputFile) : boolean

Compile a file with a given compiler and cache it.

Parameters

\Phug\CompilerInterface $compiler
string $path
string $inputFile

Returns

boolean

normalizePath()

normalizePath(\Phug\CompilerInterface  $compiler, string  $path, string  $directory) : string

Compile a file with a given compiler and cache it.

Parameters

\Phug\CompilerInterface $compiler
string $path
string $directory

Returns

string

hashPrint()

hashPrint(string  $input) : string

Return a hashed print from input file or content.

Parameters

string $input

Returns

string

getRegistryPathChunks()

getRegistryPathChunks(string  $source, integer|null  $directoryIndex = null) : \Phug\Renderer\Partial\iterable

Yield list of path chunks for registry for a given path.

Parameters

string $source
integer|null $directoryIndex

Returns

\Phug\Renderer\Partial\iterable

getFirstRegistryIndex()

getFirstRegistryIndex(array|null  $registry) : string|false

Return the first value indexed with "i:" prefix as raw cash path.

Parameters

array|null $registry

registry result

Returns

string|false

findCachePathInRegistry()

findCachePathInRegistry(string  $path, array  $registry, array<mixed,string>  $extensions = array()) : string|false

Find the path of a cached file for a given path in a given registry.

Parameters

string $path

path to find in the registry

array $registry

registry data array

array<mixed,string> $extensions

extensions to try to add to the file path if not found

Returns

string|false

findCachePathInRegistryFile()

findCachePathInRegistryFile(string  $path, string  $registryFile, array<mixed,string>  $extensions = array()) : string|false

Find the path of a cached file for a given path in a given registry file (that may not exist).

Parameters

string $path

path to find in the registry

string $registryFile

registry file path

array<mixed,string> $extensions

extensions to try to add to the file path if not found

Returns

string|false

execute()

execute(\Closure  $execution, array  $variables) 

Bind context ($this) to a given closure if passed in local variables, and bind the current adapter as __pug_adapter variable.

Parameters

\Closure $execution

Function to be executed to render/display the rendered template.

array $variables

Render local variables.

registerCachedFile()

registerCachedFile(  $directoryIndex,   $source,   $cacheFile) 

Parameters

$directoryIndex
$source
$cacheFile

createTemporaryFile()

createTemporaryFile() 

getCompiledFile()

getCompiledFile(  $php) 

Parameters

$php

tryExtensionsOnFileKey()

tryExtensionsOnFileKey(array  $registry, string  $key, array<mixed,string>  $extensions) : boolean|mixed

Try to append extension to find a key in a given array if it's file registry key.

Parameters

array $registry
string $key
array<mixed,string> $extensions

Returns

boolean|mixed

tryExtensions()

tryExtensions(array  $registry, string  $key, array<mixed,string>  $extensions) : boolean|mixed

Try to append extension to find a key in a given array assuming it's file registry key.

Parameters

array $registry
string $key
array<mixed,string> $extensions

Returns

boolean|mixed

findInRegistry()

findInRegistry(string  $path, array  $registry, array<mixed,string>  $extensions) : string|array|false

Find raw entry of a cached file for a given path in a given registry.

Parameters

string $path

path to find in the registry

array $registry

registry data array

array<mixed,string> $extensions

extensions to try to add to the file path if not found

Returns

string|array|false

handleOptionName()

handleOptionName(string  $name) : string

Parameters

string $name

Returns

string

filterTraversable()

filterTraversable(  $values) 

Parameters

$values

setOptionArrays()

setOptionArrays(array  $arrays, string  $functionName) : $this

Parameters

array $arrays
string $functionName

Returns

$this

mergeOptionValue()

mergeOptionValue(  $name,   $current,   $addedValue,   $functionName) 

Parameters

$name
$current
$addedValue
$functionName

setDefaultOption()

setDefaultOption(  $key,   $value) 

Parameters

$key
$value

withVariableReference()

withVariableReference(mixed  $variable,   $name, callable  $callback) : \Phug\Util\Partial\&$options

Parameters

mixed $variable
$name
callable $callback

Returns

\Phug\Util\Partial\&$options

withOptionReference()

withOptionReference(  $name, callable  $callback) : \Phug\Util\Partial\&$options

Parameters

$name
callable $callback

Returns

\Phug\Util\Partial\&$options

getRawCachePath()

getRawCachePath(string  $file) : string

Return a file path in the cache for a given name (without extension added).

Parameters

string $file

Returns

string

getCachePath()

getCachePath(string  $name) : string

Return a file path with extension added in the cache for a given name.

Parameters

string $name

Returns

string

hasExpiredImport()

hasExpiredImport(  $sourcePath,   $cachePath) : boolean

Returns true if the path has an expired imports linked.

Parameters

$sourcePath
$cachePath

Returns

boolean

getRegistryPath()

getRegistryPath(string  $path, array<mixed,string>  $extensions = array()) : string|false

Get path from the cache registry (if up_to_date_check set to false only).

Parameters

string $path

required view path.

array<mixed,string> $extensions

optional list of extensions to try.

Returns

string|false —

false if no path registered, the path else.

checkPathExpiration()

checkPathExpiration(  $path) 

Parameters

$path

isCacheUpToDate()

isCacheUpToDate(\Phug\Renderer\Adapter\&string  $path, string  $input = null) : boolean

Return true if the file or content is up to date in the cache folder, false else.

Parameters

\Phug\Renderer\Adapter\&string $path

to be filled

string $input

file or pug code

Returns

boolean

getCacheDirectory()

getCacheDirectory()