Factory

class Factory implements Factory (View source)

Properties

protected EngineResolver $engines The engine implementation.
protected ViewFinderInterface $finder The view finder implementation.
protected Dispatcher $events The event dispatcher instance.
protected Container $container The IoC container instance.
protected array $shared Data that should be available to all templates.
protected array $aliases Array of registered view name aliases.
protected array $names All of the registered view names.
protected array $extensions The extension to engine bindings.
protected array $composers The view composer events.
protected array $sections All of the finished, captured sections.
protected array $sectionStack The stack of in-progress sections.
protected array $pushes All of the finished, captured push sections.
protected array $pushStack The stack of in-progress push sections.
protected int $renderCount The number of active rendering operations.

Methods

void __construct(EngineResolver $engines, ViewFinderInterface $finder, Dispatcher $events)

Create a new view factory instance.

View file(string $path, array $data = [], array $mergeData = [])

Get the evaluated view contents for the given view.

View make(string $view, array $data = [], array $mergeData = [])

Get the evaluated view contents for the given view.

string normalizeName(string $name)

Normalize a view name.

array parseData(mixed $data)

Parse the given data into a raw array.

View of(string $view, mixed $data = [])

Get the evaluated view contents for a named view.

void name(string $view, string $name)

Register a named view.

void alias(string $view, string $alias)

Add an alias for a view.

bool exists(string $view)

Determine if a given view exists.

string renderEach(string $view, array $data, string $iterator, string $empty = 'raw|')

Get the rendered contents of a partial from a loop.

EngineInterface getEngineFromPath(string $path)

Get the appropriate view engine for the given path.

string getExtension(string $path)

Get the extension used by the view file.

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

Add a piece of shared data to the environment.

array creator(array|string $views, Closure|string $callback)

Register a view creator event.

array composers(array $composers)

Register multiple view composers via an array.

array composer(array|string $views, Closure|string $callback, int|null $priority = null)

Register a view composer event.

Closure|null addViewEvent(string $view, Closure|string $callback, string $prefix = 'composing: ', int|null $priority = null)

Add an event for a given view.

Closure addClassEvent(string $view, string $class, string $prefix, int|null $priority = null)

Register a class based view composer.

void addEventListener(string $name, Closure $callback, int|null $priority = null)

Add a listener to the event dispatcher.

Closure buildClassEventCallback(string $class, string $prefix)

Build a class based container callback Closure.

array parseClassEvent(string $class, string $prefix)

Parse a class based composer name.

void callComposer(View $view)

Call the composer for a given view.

void callCreator(View $view)

Call the creator for a given view.

void startSection(string $section, string $content = '')

Start injecting content into a section.

void inject(string $section, string $content)

Inject inline content into a section.

string yieldSection()

Stop injecting content into a section and return its contents.

string stopSection(bool $overwrite = false)

Stop injecting content into a section.

string appendSection()

Stop injecting content into a section and append it.

void extendSection(string $section, string $content)

Append content to a given section.

string yieldContent(string $section, string $default = '')

Get the string contents of a section.

void startPush(string $section, string $content = '')

Start injecting content into a push section.

string stopPush()

Stop injecting content into a push section.

void extendPush(string $section, string $content)

Append content to a given push section.

string yieldPushContent(string $section, string $default = '')

Get the string contents of a push section.

void flushSections()

Flush all of the section contents.

void flushSectionsIfDoneRendering()

Flush all of the section contents if done rendering.

void incrementRender()

Increment the rendering counter.

void decrementRender()

Decrement the rendering counter.

bool doneRendering()

Check if there are no active render operations.

void addLocation(string $location)

Add a location to the array of view locations.

void addNamespace(string $namespace, string|array $hints)

Add a new namespace to the loader.

void prependNamespace(string $namespace, string|array $hints)

Prepend a new namespace to the loader.

void addExtension(string $extension, string $engine, Closure $resolver = null)

Register a valid view extension and its engine.

array getExtensions()

Get the extension to engine bindings.

EngineResolver getEngineResolver()

Get the engine resolver instance.

ViewFinderInterface getFinder()

Get the view finder instance.

void setFinder(ViewFinderInterface $finder)

Set the view finder instance.

Dispatcher getDispatcher()

Get the event dispatcher instance.

void setDispatcher(Dispatcher $events)

Set the event dispatcher instance.

Container getContainer()

Get the IoC container instance.

void setContainer(Container $container)

Set the IoC container instance.

mixed shared(string $key, mixed $default = null)

Get an item from the shared data.

array getShared()

Get all of the shared data for the environment.

bool hasSection(string $name)

Check if section exists.

array getSections()

Get the entire array of sections.

array getNames()

Get all of the registered named views in environment.

Details

void __construct(EngineResolver $engines, ViewFinderInterface $finder, Dispatcher $events)

Create a new view factory instance.

Parameters

EngineResolver $engines
ViewFinderInterface $finder
Dispatcher $events

Return Value

void

View file(string $path, array $data = [], array $mergeData = [])

Get the evaluated view contents for the given view.

Parameters

string $path
array $data
array $mergeData

Return Value

View

View make(string $view, array $data = [], array $mergeData = [])

Get the evaluated view contents for the given view.

Parameters

string $view
array $data
array $mergeData

Return Value

View

protected string normalizeName(string $name)

Normalize a view name.

Parameters

string $name

Return Value

string

protected array parseData(mixed $data)

Parse the given data into a raw array.

Parameters

mixed $data

Return Value

array

View of(string $view, mixed $data = [])

Get the evaluated view contents for a named view.

Parameters

string $view
mixed $data

Return Value

View

void name(string $view, string $name)

Register a named view.

Parameters

string $view
string $name

Return Value

void

void alias(string $view, string $alias)

Add an alias for a view.

Parameters

string $view
string $alias

Return Value

void

bool exists(string $view)

Determine if a given view exists.

Parameters

string $view

Return Value

bool

string renderEach(string $view, array $data, string $iterator, string $empty = 'raw|')

Get the rendered contents of a partial from a loop.

Parameters

string $view
array $data
string $iterator
string $empty

Return Value

string

EngineInterface getEngineFromPath(string $path)

Get the appropriate view engine for the given path.

Parameters

string $path

Return Value

EngineInterface

Exceptions

InvalidArgumentException

protected string getExtension(string $path)

Get the extension used by the view file.

Parameters

string $path

Return Value

string

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

Add a piece of shared data to the environment.

Parameters

array|string $key
mixed $value

Return Value

mixed

array creator(array|string $views, Closure|string $callback)

Register a view creator event.

Parameters

array|string $views
Closure|string $callback

Return Value

array

array composers(array $composers)

Register multiple view composers via an array.

Parameters

array $composers

Return Value

array

array composer(array|string $views, Closure|string $callback, int|null $priority = null)

Register a view composer event.

Parameters

array|string $views
Closure|string $callback
int|null $priority

Return Value

array

protected Closure|null addViewEvent(string $view, Closure|string $callback, string $prefix = 'composing: ', int|null $priority = null)

Add an event for a given view.

Parameters

string $view
Closure|string $callback
string $prefix
int|null $priority

Return Value

Closure|null

protected Closure addClassEvent(string $view, string $class, string $prefix, int|null $priority = null)

Register a class based view composer.

Parameters

string $view
string $class
string $prefix
int|null $priority

Return Value

Closure

protected void addEventListener(string $name, Closure $callback, int|null $priority = null)

Add a listener to the event dispatcher.

Parameters

string $name
Closure $callback
int|null $priority

Return Value

void

protected Closure buildClassEventCallback(string $class, string $prefix)

Build a class based container callback Closure.

Parameters

string $class
string $prefix

Return Value

Closure

protected array parseClassEvent(string $class, string $prefix)

Parse a class based composer name.

Parameters

string $class
string $prefix

Return Value

array

void callComposer(View $view)

Call the composer for a given view.

Parameters

View $view

Return Value

void

void callCreator(View $view)

Call the creator for a given view.

Parameters

View $view

Return Value

void

void startSection(string $section, string $content = '')

Start injecting content into a section.

Parameters

string $section
string $content

Return Value

void

void inject(string $section, string $content)

Inject inline content into a section.

Parameters

string $section
string $content

Return Value

void

string yieldSection()

Stop injecting content into a section and return its contents.

Return Value

string

string stopSection(bool $overwrite = false)

Stop injecting content into a section.

Parameters

bool $overwrite

Return Value

string

Exceptions

InvalidArgumentException

string appendSection()

Stop injecting content into a section and append it.

Return Value

string

Exceptions

InvalidArgumentException

protected void extendSection(string $section, string $content)

Append content to a given section.

Parameters

string $section
string $content

Return Value

void

string yieldContent(string $section, string $default = '')

Get the string contents of a section.

Parameters

string $section
string $default

Return Value

string

void startPush(string $section, string $content = '')

Start injecting content into a push section.

Parameters

string $section
string $content

Return Value

void

string stopPush()

Stop injecting content into a push section.

Return Value

string

Exceptions

InvalidArgumentException

protected void extendPush(string $section, string $content)

Append content to a given push section.

Parameters

string $section
string $content

Return Value

void

string yieldPushContent(string $section, string $default = '')

Get the string contents of a push section.

Parameters

string $section
string $default

Return Value

string

void flushSections()

Flush all of the section contents.

Return Value

void

void flushSectionsIfDoneRendering()

Flush all of the section contents if done rendering.

Return Value

void

void incrementRender()

Increment the rendering counter.

Return Value

void

void decrementRender()

Decrement the rendering counter.

Return Value

void

bool doneRendering()

Check if there are no active render operations.

Return Value

bool

void addLocation(string $location)

Add a location to the array of view locations.

Parameters

string $location

Return Value

void

void addNamespace(string $namespace, string|array $hints)

Add a new namespace to the loader.

Parameters

string $namespace
string|array $hints

Return Value

void

void prependNamespace(string $namespace, string|array $hints)

Prepend a new namespace to the loader.

Parameters

string $namespace
string|array $hints

Return Value

void

void addExtension(string $extension, string $engine, Closure $resolver = null)

Register a valid view extension and its engine.

Parameters

string $extension
string $engine
Closure $resolver

Return Value

void

array getExtensions()

Get the extension to engine bindings.

Return Value

array

EngineResolver getEngineResolver()

Get the engine resolver instance.

Return Value

EngineResolver

ViewFinderInterface getFinder()

Get the view finder instance.

Return Value

ViewFinderInterface

void setFinder(ViewFinderInterface $finder)

Set the view finder instance.

Parameters

ViewFinderInterface $finder

Return Value

void

Dispatcher getDispatcher()

Get the event dispatcher instance.

Return Value

Dispatcher

void setDispatcher(Dispatcher $events)

Set the event dispatcher instance.

Parameters

Dispatcher $events

Return Value

void

Container getContainer()

Get the IoC container instance.

Return Value

Container

void setContainer(Container $container)

Set the IoC container instance.

Parameters

Container $container

Return Value

void

mixed shared(string $key, mixed $default = null)

Get an item from the shared data.

Parameters

string $key
mixed $default

Return Value

mixed

array getShared()

Get all of the shared data for the environment.

Return Value

array

bool hasSection(string $name)

Check if section exists.

Parameters

string $name

Return Value

bool

array getSections()

Get the entire array of sections.

Return Value

array

array getNames()

Get all of the registered named views in environment.

Return Value

array

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.2/Illuminate/View/Factory.html