View class

Framework\MVC\View

Class View.

Defined in libraries/mvc/src/View.php

Properties #

$baseDir
-
$extension
-
$layout
-
$openBlock
-
$openBlocks
-
$layoutsOpen
-
$blocks
-
$currentView
-
$debugCollector
-
$layoutPrefix
-
$includePrefix
-
$inInclude
-
$showDebugComments
-
$viewsPaths
-
$instanceName
-
$throwExceptionsInDestructor
-

$baseDir

protected ?string $baseDir = NULL

$extension

protected string $extension

$layout

protected string $layout

$openBlock

protected ?string $openBlock

$openBlocks

protected array $openBlocks = array ( )

$layoutsOpen

protected array $layoutsOpen = array ( )

$blocks

protected array $blocks

$currentView

protected string $currentView

$debugCollector

protected \Framework\MVC\Debug\ViewsCollector $debugCollector

$layoutPrefix

protected string $layoutPrefix = ''

$includePrefix

protected string $includePrefix = ''

$inInclude

protected bool $inInclude = false

$showDebugComments

protected bool $showDebugComments = true

$viewsPaths

protected array $viewsPaths = array ( )

$instanceName

protected string $instanceName

$throwExceptionsInDestructor

protected bool $throwExceptionsInDestructor = true

Methods #

__construct()
-
__destruct()
-
block()
Open a block.
currentBlock()
Tells the name of the current block.
disableDebugComments()
Disable debug comments when in debug mode.
enableDebugComments()
Enable debug comments when in debug mode.
endBlock()
Close an open block.
extends()
Extends a layout.
extendsWithoutPrefix()
Extends a layout without prefix.
getBaseDir()
Get the base directory.
getExtension()
Get the extension of view files.
getIncludePrefix()
Get the name of the includes directory.
getInstanceName()
-
getInstanceNameWithPath()
-
getLayoutPrefix()
Get the name of the layouts directory.
hasBlock()
Tells whether a given block is set.
inBlock()
Tells whether the current content is inside a block.
inLayout()
Tells whether the current contents is inside a layout.
include()
Returns the contents of an include.
includeWithoutPrefix()
Returns the contents of an include without prefix.
isShowingDebugComments()
Tells if it is showing debug comments when in debug mode.
isThrowExceptionsInDestructor()
Tells whether it is able to throw exceptions in the destructor.
removeBlock()
Remove a block.
render()
Render a view file.
renderBlock()
Render a block.
setBaseDir()
Sets the base directory where the views files are located.
setDebugCollector()
-
setExtension()
Set the extension of views files.
setIncludePrefix()
Set the name of a directory for includes within the base directory.
setInstanceName()
-
setLayoutPrefix()
Set the name of a directory for layouts within the base directory.
setThrowExceptionsInDestructor()
Enables/disables exceptions in the destructor.
getCommentPath()
-
getContents()
-
getFilepath()
-
getIncludeContents()
-
getIncludeContentsWithDebug()
-
getNamespacedFilepath()
-
involveInclude()
-
makeDirectoryPrefix()
-
setDebugData()
-

__construct()

public function __construct(?string $baseDir = NULL, string $extension = '.php')
Parameters
  • ?string $baseDir
  • string $extension

__destruct()

public function __destruct()

block()

public function block(string $name): static

Open a block.

Parameters
  • string $name - Block name
Returns static

currentBlock()

public function currentBlock(): ?string

Tells the name of the current block.

Returns ?string

disableDebugComments()

public function disableDebugComments(): static

Disable debug comments when in debug mode.

Returns static

enableDebugComments()

public function enableDebugComments(): static

Enable debug comments when in debug mode.

Returns static

endBlock()

public function endBlock(): static

Close an open block.

Returns static

extends()

public function extends(string $layout, ?string $openBlock = NULL): static

Extends a layout.

Parameters
  • string $layout - The name of the file within the layouts directory
  • ?string $openBlock - Optionally opens and closes this block automatically
Returns static

extendsWithoutPrefix()

public function extendsWithoutPrefix(string $layout): static

Extends a layout without prefix.

Parameters
  • string $layout - The name of the file within the base directory
Returns static

getBaseDir()

public function getBaseDir(): ?string

Get the base directory.

Returns ?string

getExtension()

public function getExtension(): string

Get the extension of view files.

Returns string

getIncludePrefix()

public function getIncludePrefix(): string

Get the name of the includes directory.

Returns string

getInstanceName()

public function getInstanceName(): string
Returns string

getInstanceNameWithPath()

public function getInstanceNameWithPath(string $name): string
Parameters
  • string $name
Returns string

getLayoutPrefix()

public function getLayoutPrefix(): string

Get the name of the layouts directory.

Returns string

hasBlock()

public function hasBlock(string $name): bool

Tells whether a given block is set.

Parameters
  • string $name - Block name
Returns bool

inBlock()

public function inBlock(string $name): bool

Tells whether the current content is inside a block.

Parameters
  • string $name - Block name
Returns bool

inLayout()

public function inLayout(string $layout): bool

Tells whether the current contents is inside a layout.

Parameters
  • string $layout
Returns bool

include()

public function include(string $view, array $data = array ( )): string

Returns the contents of an include.

Parameters
  • string $view - The path of the file within the includes directory
  • array $data - Data passed to the view. The array keys will be variables
Returns string

includeWithoutPrefix()

public function includeWithoutPrefix(string $view, array $data = array ( )): string

Returns the contents of an include without prefix.

Parameters
  • string $view - The path of the file within the base directory
  • array $data - Data passed to the view. The array keys will be variables
Returns string

isShowingDebugComments()

public function isShowingDebugComments(): bool

Tells if it is showing debug comments when in debug mode.

Returns bool

isThrowExceptionsInDestructor()

public function isThrowExceptionsInDestructor(): bool

Tells whether it is able to throw exceptions in the destructor.

Returns bool

removeBlock()

public function removeBlock(string $name): static

Remove a block.

Parameters
  • string $name - Block name
Returns static

render()

public function render(string $view, array $data = array ( )): string

Render a view file.

Parameters
  • string $view - View path within the base directory
  • array $data - Data passed to the view. The array keys will be variables
Returns string

renderBlock()

public function renderBlock(string $name): ?string

Render a block.

Parameters
  • string $name - Block name
Returns ?string

setBaseDir()

public function setBaseDir(string $baseDir): static

Sets the base directory where the views files are located.

Parameters
  • string $baseDir
Returns static

setDebugCollector()

public function setDebugCollector(\Framework\MVC\Debug\ViewsCollector $debugCollector): static
Parameters
  • \Framework\MVC\Debug\ViewsCollector $debugCollector
Returns static

setExtension()

public function setExtension(string $extension): static

Set the extension of views files.

Parameters
  • string $extension
Returns static

setIncludePrefix()

public function setIncludePrefix(string $prefix): static

Set the name of a directory for includes within the base directory.

Parameters
  • string $prefix
Returns static

setInstanceName()

public function setInstanceName(string $instanceName): static
Parameters
  • string $instanceName
Returns static

setLayoutPrefix()

public function setLayoutPrefix(string $prefix): static

Set the name of a directory for layouts within the base directory.

Parameters
  • string $prefix
Returns static

setThrowExceptionsInDestructor()

public function setThrowExceptionsInDestructor(bool $active = true): static

Enables/disables exceptions in the destructor.

Parameters
  • bool $active - True to throw exceptions, false otherwise
Returns static

getCommentPath()

protected function getCommentPath(string $name): string
Parameters
  • string $name
Returns string

getContents()

protected function getContents(string $view, array $data): string
Parameters
  • string $view
  • array $data
Returns string

getFilepath()

protected function getFilepath(string $view): string
Parameters
  • string $view
Returns string

getIncludeContents()

protected function getIncludeContents(string $view, array $data = array ( )): string
Parameters
  • string $view
  • array $data
Returns string

getIncludeContentsWithDebug()

protected function getIncludeContentsWithDebug(string $view, array $data = array ( )): string
Parameters
  • string $view
  • array $data
Returns string

getNamespacedFilepath()

protected function getNamespacedFilepath(string $view): string
Parameters
  • string $view
Returns string

involveInclude()

protected function involveInclude(string $view, string $contents): string
Parameters
  • string $view
  • string $contents
Returns string

makeDirectoryPrefix()

protected function makeDirectoryPrefix(string $prefix): string
Parameters
  • string $prefix
Returns string

setDebugData()

protected function setDebugData(string $file, float $start, string $type): static
Parameters
  • string $file
  • float $start
  • string $type
Returns static