Pickles Framework Documentation

PicklesEngine
in package
implements Engine

Table of Contents

Interfaces

Engine
Interface Engine

Properties

$contentAnnotation  : string
Annotation string used as a placeholder in the layout to inject rendered view content.
$defaultLayout  : string
The default layout name used when no layout is explicitly provided.
$viewsDir  : string
The base directory path where view files are stored.

Methods

__construct()  : mixed
render()  : string
Renders a view within an optional layout.
setDefaultLayout()  : self
Sets the name of the default layout used when none is provided during rendering.
setViewsDir()  : self
Sets the directory where view and layout files are located.
getPhpFileOutput()  : string
Includes a PHP file with optional parameters and returns its output as a string.
renderLayout()  : string
Renders the specified layout file and returns its output.
renderView()  : string
Renders the specified view file with the provided parameters.
validateViewFile()  : void
Validates that the specified view file exists and is not an empty string.

Properties

$contentAnnotation

Annotation string used as a placeholder in the layout to inject rendered view content.

protected string $contentAnnotation = "@content"

When rendering, this placeholder in the layout file is replaced by the output of the view. By default, it is set to "@content", but it can be customized if needed.

$defaultLayout

The default layout name used when no layout is explicitly provided.

protected string $defaultLayout = "main"

The layout is expected to be located in the layouts subdirectory within the views directory, and the corresponding file should have a .php extension (e.g., "main.php").

$viewsDir

The base directory path where view files are stored.

protected string $viewsDir

This path is used to locate both the layout and individual view PHP files. It can be absolute or relative, depending on the application context.

Methods

__construct()

public __construct(string $viewsDir) : mixed
Parameters
$viewsDir : string

render()

Renders a view within an optional layout.

public render(string $view[, array<string|int, mixed> $params = [] ][, string|null $layout = null ]) : string

The specified view is rendered using the given parameters, and its content is injected into a layout template by replacing the configured content annotation.

Parameters
$view : string

The name of the view file (without .php extension).

$params : array<string|int, mixed> = []

Associative array of variables to extract into the view scope.

$layout : string|null = null

Optional layout name. If null, the default layout is used.

Tags
throws
FileNotFoundException

If the view file does not exist or the name is empty.

Return values
string —

The final rendered output with the view embedded in the layout.

setDefaultLayout()

Sets the name of the default layout used when none is provided during rendering.

public setDefaultLayout(string $defaultLayout) : self
Parameters
$defaultLayout : string

The new default layout name (without .php extension).

Return values
self —

Returns the current instance for method chaining.

setViewsDir()

Sets the directory where view and layout files are located.

public setViewsDir(string $viewsDir) : self
Parameters
$viewsDir : string

Absolute or relative path to the views directory.

Return values
self —

Returns the current instance for method chaining.

getPhpFileOutput()

Includes a PHP file with optional parameters and returns its output as a string.

protected getPhpFileOutput(string $phpFile[, array<string|int, mixed> $params = [] ]) : string

Parameters are extracted into the local scope before including the file. Output buffering is used to capture the rendered result.

Parameters
$phpFile : string

Full path to the PHP file to include.

$params : array<string|int, mixed> = []

Optional associative array of variables to make available in the file.

Return values
string —

The output generated by the PHP file.

renderLayout()

Renders the specified layout file and returns its output.

protected renderLayout(string $layout) : string

This method locates the layout file within the layouts/ directory under the views directory and includes it using output buffering.

Parameters
$layout : string

The name of the layout file (without .php extension).

Return values
string —

The rendered layout output as a string.

renderView()

Renders the specified view file with the provided parameters.

protected renderView(string $view[, array<string|int, mixed> $params = [] ]) : string

The parameters are extracted as local variables available to the view file.

Parameters
$view : string

The name of the view file (without .php extension).

$params : array<string|int, mixed> = []

Associative array of variables to extract into the view scope.

Return values
string —

The rendered view output.

validateViewFile()

Validates that the specified view file exists and is not an empty string.

private validateViewFile(string $viewsDir, string $view) : void

Throws an exception if the file does not exist or if the view name is empty.

Parameters
$viewsDir : string

Base directory where views are located.

$view : string

Name of the view file (without .php extension).

Tags
throws
FileNotFoundException

If the file is not found or the view name is empty.


        
On this page

Search results