class View implements ArrayAccess, Htmlable, Stringable, View

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected array $data

The array of view data.

Methods

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically bind parameters to the view.

__construct(Factory $factory, Engine $engine, string $view, string $path, mixed $data = [])

Create a new view instance.

fragment(string $fragment)

Get the evaluated contents of a given fragment.

string
fragments(array|null $fragments = null)

Get the evaluated contents for a given array of fragments or return all fragments.

string|Htmlable
fragmentIf(bool $boolean, string $fragment)

Get the evaluated contents of a given fragment if the given condition is true.

string
fragmentsIf(bool $boolean, array|null $fragments = null)

Get the evaluated contents for a given array of fragments if the given condition is true.

string
allFragments()

Get all fragments as a single string.

string
render(callable|null $callback = null)

Get the string contents of the view.

mixed
doRender(callable|null $callback = null)

No description

string
renderContents()

Get the contents of the view instance.

string
getContents()

Get the evaluated contents of the view.

array
gatherData()

Get the data bound to the view instance.

array
renderSections()

Get the sections of the rendered view.

with(string|array $key, mixed $value = null)

Add a piece of data to the view.

nest(string $key, string $view, array $data = [])

Add a view instance to the view data.

withErrors(MessageProvider|array|string $provider, string $bag = 'default')

Add validation errors to the view.

formatErrors(MessageProvider|array|string $provider)

Parse the given errors into an appropriate value.

string
name()

Get the name of the view.

string
getName()

Get the name of the view.

array
getData()

Get the array of view data.

string
getPath()

Get the path to the view file.

void
setPath(string $path)

Set the path to the view.

getFactory()

Get the view factory instance.

getEngine()

Get the view's rendering engine.

bool
offsetExists(mixed $key)

Determine if a piece of data is bound.

mixed
offsetGet(mixed $key)

Get a piece of bound data to the view.

void
offsetSet(mixed $key, mixed $value)

Set a piece of data on the view.

void
offsetUnset(mixed $key)

Unset a piece of data from the view.

static void
flushState()

Flush all static state.

mixed
__get(string $key)

Get a piece of data from the view.

void
__set(string $key, mixed $value)

Set a piece of data on the view.

bool
__isset(string $key)

Check if a piece of data is bound to the view.

void
__unset(string $key)

Remove a piece of bound data from the view.

string
toHtml()

Get content as a string of HTML.

string
__toString()

Get the string contents of the view.

Details

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 396
mixed __call(string $method, array $parameters)

Dynamically bind parameters to the view.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 39
__construct(Factory $factory, Engine $engine, string $view, string $path, mixed $data = [])

Create a new view instance.

Parameters

Factory $factory
Engine $engine
string $view
string $path
mixed $data

at line 52
HtmlString fragment(string $fragment)

Get the evaluated contents of a given fragment.

Parameters

string $fragment

Return Value

HtmlString

at line 64
string fragments(array|null $fragments = null)

Get the evaluated contents for a given array of fragments or return all fragments.

Parameters

array|null $fragments

Return Value

string

at line 74
string|Htmlable fragmentIf(bool $boolean, string $fragment)

Get the evaluated contents of a given fragment if the given condition is true.

Parameters

bool $boolean
string $fragment

Return Value

string|Htmlable

at line 86
string fragmentsIf(bool $boolean, array|null $fragments = null)

Get the evaluated contents for a given array of fragments if the given condition is true.

Parameters

bool $boolean
array|null $fragments

Return Value

string

at line 98
protected string allFragments()

Get all fragments as a single string.

Return Value

string

at line 109
string render(callable|null $callback = null)

Get the string contents of the view.

Parameters

callable|null $callback

Return Value

string

Exceptions

Throwable

at line 122
protected mixed doRender(callable|null $callback = null)

No description

Parameters

callable|null $callback

Return Value

mixed

Exceptions

Throwable

at line 145
protected string renderContents()

Get the contents of the view instance.

Return Value

string

at line 169
protected string getContents()

Get the evaluated contents of the view.

Return Value

string

at line 177
array gatherData()

Get the data bound to the view instance.

Return Value

array

at line 198
array renderSections()

Get the sections of the rendered view.

This function is similar to render. We need to call renderContents function first. Because sections are only populated during the view rendering process.

Return Value

array

Exceptions

Throwable

at line 221
View with(string|array $key, mixed $value = null)

Add a piece of data to the view.

Parameters

string|array $key
mixed $value

Return Value

View

at line 235
View nest(string $key, string $view, array $data = [])

Add a view instance to the view data.

Parameters

string $key
string $view
array $data

Return Value

View

at line 243
View withErrors(MessageProvider|array|string $provider, string $bag = 'default')

Add validation errors to the view.

Parameters

MessageProvider|array|string $provider
string $bag

Return Value

View

at line 254
protected MessageBag formatErrors(MessageProvider|array|string $provider)

Parse the given errors into an appropriate value.

Parameters

MessageProvider|array|string $provider

Return Value

MessageBag

at line 264
string name()

Get the name of the view.

Return Value

string

at line 272
string getName()

Get the name of the view.

Return Value

string

at line 280
array getData()

Get the array of view data.

Return Value

array

at line 288
string getPath()

Get the path to the view file.

Return Value

string

at line 296
void setPath(string $path)

Set the path to the view.

Parameters

string $path

Return Value

void

at line 304
Factory getFactory()

Get the view factory instance.

Return Value

Factory

at line 312
Engine getEngine()

Get the view's rendering engine.

Return Value

Engine

at line 320
bool offsetExists(mixed $key)

Determine if a piece of data is bound.

Parameters

mixed $key

Return Value

bool

at line 328
mixed offsetGet(mixed $key)

Get a piece of bound data to the view.

Parameters

mixed $key

Return Value

mixed

at line 336
void offsetSet(mixed $key, mixed $value)

Set a piece of data on the view.

Parameters

mixed $key
mixed $value

Return Value

void

at line 344
void offsetUnset(mixed $key)

Unset a piece of data from the view.

Parameters

mixed $key

Return Value

void

at line 352
static void flushState()

Flush all static state.

Return Value

void

at line 360
mixed __get(string $key)

Get a piece of data from the view.

Parameters

string $key

Return Value

mixed

at line 368
void __set(string $key, mixed $value)

Set a piece of data on the view.

Parameters

string $key
mixed $value

Return Value

void

at line 376
bool __isset(string $key)

Check if a piece of data is bound to the view.

Parameters

string $key

Return Value

bool

at line 384
void __unset(string $key)

Remove a piece of bound data from the view.

Parameters

string $key

Return Value

void

at line 418
string toHtml()

Get content as a string of HTML.

Return Value

string

Exceptions

Throwable

at line 428
string __toString()

Get the string contents of the view.

Return Value

string

Exceptions

Throwable