Factory

class Factory implements Factory (View source)

Traits

ManagesComponents
ManagesEvents
ManagesLayouts
ManagesLoops
ManagesStacks
ManagesTranslations

Properties

protected array $componentStack The components being rendered. from ManagesComponents
protected array $componentData The original data passed to the component. from ManagesComponents
protected array $slots The slot contents for the component. from ManagesComponents
protected array $slotStack The names of the slots being rendered. from ManagesComponents
protected array $sections All of the finished, captured sections. from ManagesLayouts
protected array $sectionStack The stack of in-progress sections. from ManagesLayouts
static protected mixed $parentPlaceholder The parent placeholder for the request. from ManagesLayouts
protected array $loopsStack The stack of in-progress loops. from ManagesLoops
protected array $pushes All of the finished, captured push sections. from ManagesStacks
protected array $prepends All of the finished, captured prepend sections. from ManagesStacks
protected array $pushStack The stack of in-progress push sections. from ManagesStacks
protected array $translationReplacements The translation replacements for the translation being rendered. from ManagesTranslations
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 $extensions The extension to engine bindings.
protected array $composers The view composer events.
protected int $renderCount The number of active rendering operations.

Methods

void startComponent(string $name, array $data = [])

Start a component rendering process.

from ManagesComponents
string renderComponent()

Render the current component.

from ManagesComponents
array componentData(string $name)

Get the data for the given component.

from ManagesComponents
void slot(string $name, string|null $content = null)

Start the slot rendering process.

from ManagesComponents
void endSlot()

Save the slot content for rendering.

from ManagesComponents
int currentComponent()

Get the index for the current component.

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

Register a view creator event.

from ManagesEvents
array composers(array $composers)

Register multiple view composers via an array.

from ManagesEvents
array composer(array|string $views, Closure|string $callback)

Register a view composer event.

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

Add an event for a given view.

from ManagesEvents
Closure addClassEvent(string $view, string $class, string $prefix)

Register a class based view composer.

from ManagesEvents
Closure buildClassEventCallback(string $class, string $prefix)

Build a class based container callback Closure.

from ManagesEvents
array parseClassEvent(string $class, string $prefix)

Parse a class based composer name.

from ManagesEvents
string classEventMethodForPrefix(string $prefix)

Determine the class event method based on the given prefix.

from ManagesEvents
void addEventListener(string $name, Closure $callback)

Add a listener to the event dispatcher.

from ManagesEvents
void callComposer(View $view)

Call the composer for a given view.

from ManagesEvents
void callCreator(View $view)

Call the creator for a given view.

from ManagesEvents
void startSection(string $section, string|null $content = null)

Start injecting content into a section.

from ManagesLayouts
void inject(string $section, string $content)

Inject inline content into a section.

from ManagesLayouts
string yieldSection()

Stop injecting content into a section and return its contents.

from ManagesLayouts
string stopSection(bool $overwrite = false)

Stop injecting content into a section.

from ManagesLayouts
string appendSection()

Stop injecting content into a section and append it.

from ManagesLayouts
void extendSection(string $section, string $content)

Append content to a given section.

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

Get the string contents of a section.

from ManagesLayouts
static string parentPlaceholder(string $section = '')

Get the parent placeholder for the current request.

from ManagesLayouts
bool hasSection(string $name)

Check if section exists.

from ManagesLayouts
mixed getSection(string $name, string $default = null)

Get the contents of a section.

from ManagesLayouts
array getSections()

Get the entire array of sections.

from ManagesLayouts
void flushSections()

Flush all of the sections.

from ManagesLayouts
void addLoop(Countable|array $data)

Add new loop to the stack.

from ManagesLoops
void incrementLoopIndices()

Increment the top loop's indices.

from ManagesLoops
void popLoop()

Pop a loop from the top of the loop stack.

from ManagesLoops
stdClass|null getLastLoop()

Get an instance of the last loop in the stack.

from ManagesLoops
array getLoopStack()

Get the entire loop stack.

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

Start injecting content into a push section.

from ManagesStacks
string stopPush()

Stop injecting content into a push section.

from ManagesStacks
void extendPush(string $section, string $content)

Append content to a given push section.

from ManagesStacks
void startPrepend(string $section, string $content = '')

Start prepending content into a push section.

from ManagesStacks
string stopPrepend()

Stop prepending content into a push section.

from ManagesStacks
void extendPrepend(string $section, string $content)

Prepend content to a given stack.

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

Get the string contents of a push section.

from ManagesStacks
void flushStacks()

Flush all of the stacks.

from ManagesStacks
void startTranslation(array $replacements = [])

Start a translation block.

from ManagesTranslations
string renderTranslation()

Render the current translation.

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

Create a new view factory instance.

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

Get the evaluated view contents for the given view.

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

Get the evaluated view contents for the given view.

View first(array $views, Arrayable|array $data = [], array $mergeData = [])

Get the first view that actually exists from the given list.

string renderWhen(bool $condition, string $view, Arrayable|array $data = [], array $mergeData = [])

Get the rendered content of the view based on a given condition.

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

Get the rendered contents of a partial from a loop.

string normalizeName(string $name)

Normalize a view name.

array parseData(mixed $data)

Parse the given data into a raw array.

View viewInstance(string $view, string $path, Arrayable|array $data)

Create a new view instance from the given arguments.

bool exists(string $view)

Determine if a given view exists.

Engine 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.

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.

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

Add a new namespace to the loader.

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

Prepend a new namespace to the loader.

$this replaceNamespace(string $namespace, string|array $hints)

Replace the namespace hints for the given namespace.

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

Register a valid view extension and its engine.

void flushState()

Flush all of the factory state like sections and stacks.

void flushStateIfDoneRendering()

Flush all of the section contents if done rendering.

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.

void flushFinderCache()

Flush the cache of views located by the finder.

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.

Details

void startComponent(string $name, array $data = [])

Start a component rendering process.

Parameters

string $name
array $data

Return Value

void

string renderComponent()

Render the current component.

Return Value

string

protected array componentData(string $name)

Get the data for the given component.

Parameters

string $name

Return Value

array

void slot(string $name, string|null $content = null)

Start the slot rendering process.

Parameters

string $name
string|null $content

Return Value

void

void endSlot()

Save the slot content for rendering.

Return Value

void

protected int currentComponent()

Get the index for the current component.

Return Value

int

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)

Register a view composer event.

Parameters

array|string $views
Closure|string $callback

Return Value

array

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

Add an event for a given view.

Parameters

string $view
Closure|string $callback
string $prefix

Return Value

Closure|null

protected Closure addClassEvent(string $view, string $class, string $prefix)

Register a class based view composer.

Parameters

string $view
string $class
string $prefix

Return Value

Closure

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

protected string classEventMethodForPrefix(string $prefix)

Determine the class event method based on the given prefix.

Parameters

string $prefix

Return Value

string

protected void addEventListener(string $name, Closure $callback)

Add a listener to the event dispatcher.

Parameters

string $name
Closure $callback

Return Value

void

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|null $content = null)

Start injecting content into a section.

Parameters

string $section
string|null $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

static string parentPlaceholder(string $section = '')

Get the parent placeholder for the current request.

Parameters

string $section

Return Value

string

bool hasSection(string $name)

Check if section exists.

Parameters

string $name

Return Value

bool

mixed getSection(string $name, string $default = null)

Get the contents of a section.

Parameters

string $name
string $default

Return Value

mixed

array getSections()

Get the entire array of sections.

Return Value

array

void flushSections()

Flush all of the sections.

Return Value

void

void addLoop(Countable|array $data)

Add new loop to the stack.

Parameters

Countable|array $data

Return Value

void

void incrementLoopIndices()

Increment the top loop's indices.

Return Value

void

void popLoop()

Pop a loop from the top of the loop stack.

Return Value

void

stdClass|null getLastLoop()

Get an instance of the last loop in the stack.

Return Value

stdClass|null

array getLoopStack()

Get the entire loop stack.

Return Value

array

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

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

Start prepending content into a push section.

Parameters

string $section
string $content

Return Value

void

string stopPrepend()

Stop prepending content into a push section.

Return Value

string

Exceptions

InvalidArgumentException

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

Prepend content to a given stack.

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 flushStacks()

Flush all of the stacks.

Return Value

void

void startTranslation(array $replacements = [])

Start a translation block.

Parameters

array $replacements

Return Value

void

string renderTranslation()

Render the current translation.

Return Value

string

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, Arrayable|array $data = [], array $mergeData = [])

Get the evaluated view contents for the given view.

Parameters

string $path
Arrayable|array $data
array $mergeData

Return Value

View

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

Get the evaluated view contents for the given view.

Parameters

string $view
Arrayable|array $data
array $mergeData

Return Value

View

View first(array $views, Arrayable|array $data = [], array $mergeData = [])

Get the first view that actually exists from the given list.

Parameters

array $views
Arrayable|array $data
array $mergeData

Return Value

View

Exceptions

InvalidArgumentException

string renderWhen(bool $condition, string $view, Arrayable|array $data = [], array $mergeData = [])

Get the rendered content of the view based on a given condition.

Parameters

bool $condition
string $view
Arrayable|array $data
array $mergeData

Return Value

string

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

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

protected View viewInstance(string $view, string $path, Arrayable|array $data)

Create a new view instance from the given arguments.

Parameters

string $view
string $path
Arrayable|array $data

Return Value

View

bool exists(string $view)

Determine if a given view exists.

Parameters

string $view

Return Value

bool

Engine getEngineFromPath(string $path)

Get the appropriate view engine for the given path.

Parameters

string $path

Return Value

Engine

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

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

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

Add a new namespace to the loader.

Parameters

string $namespace
string|array $hints

Return Value

$this

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

Prepend a new namespace to the loader.

Parameters

string $namespace
string|array $hints

Return Value

$this

$this replaceNamespace(string $namespace, string|array $hints)

Replace the namespace hints for the given namespace.

Parameters

string $namespace
string|array $hints

Return Value

$this

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

void flushState()

Flush all of the factory state like sections and stacks.

Return Value

void

void flushStateIfDoneRendering()

Flush all of the section contents if done rendering.

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

void flushFinderCache()

Flush the cache of views located by the 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

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