Factory
class Factory implements Factory
Traits
Constants
| protected RENDER_COUNT_CONTEXT_KEY |
The number of active rendering operations. |
| protected RENDERED_ONCE_CONTEXT_KEY |
The "once" block IDs that have been rendered. |
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| 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 array | $pathEngineCache | The cached array of engines for paths. |
|
| protected array | $normalizedNameCache | The cache of normalized names for views. |
|
| protected array | $renderingObservers | The registered pre-render observers. |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Start a component rendering process.
Get the first view that actually exists from the given list, and start a component.
Get an item from the component data that exists above the current component.
Start the slot rendering process.
Add an event for a given view.
Register a class based view composer.
Build a class based container callback Closure.
Parse a class based composer name.
Determine the class event method based on the given prefix.
Get the contents of a fragment.
Start injecting content into a section.
Inject inline content into a section.
Stop injecting content into a section and return its contents.
Stop injecting content into a section.
Append content to a given section.
Get the parent placeholder for the current request.
Get the contents of a section.
Start injecting content into a push section.
Append content to a given push section.
Start prepending content into a push section.
Prepend content to a given stack.
Get the string contents of a push section.
Create a new view factory instance.
Clone the factory for isolated render-time namespace changes.
Get the rendered content of the view based on a given condition.
Get the rendered content of the view based on the negation of a given condition.
Get the rendered contents of a partial from a loop.
Normalize a view name.
Parse the given data into a raw array.
Create a new view instance from the given arguments.
Determine if a given view exists.
Get the appropriate view engine for the given path.
Get the extension used by the view file.
Add a piece of shared data to the environment.
Increment the rendering counter.
Decrement the rendering counter.
Register a pre-render observer.
Get the rendering counter.
Check if there are no active render operations.
Determine if the given once token has been rendered.
Mark the given once token as having been rendered.
Add a location to the array of view locations.
Prepend a location to the array of view locations.
Add a new namespace to the loader.
Prepend a new namespace to the loader.
Replace the namespace hints for the given namespace.
Register a valid view extension and its engine.
Flush all of the factory state like sections and stacks.
Flush all of the section contents if done rendering.
Get the extension to engine bindings.
Get the engine resolver instance.
Get the view finder instance.
Flush the cache of views located by the finder.
Get the event dispatcher instance.
Get the IoC container instance.
Get an item from the shared data.
Get all of the shared data for the environment.
Merge shared data into the given view data.
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.
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.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
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.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
ManagesComponents at line 44
void
startComponent(View|Htmlable|Closure|string $view, array $data = [])
Start a component rendering process.
in
ManagesComponents at line 55
protected int
pushComponentStack(View|Htmlable|Closure|string $view)
No description
in
ManagesComponents at line 64
protected View|Htmlable|Closure|string|null
popComponentStack()
No description
in
ManagesComponents at line 73
protected void
appendComponentData(array $data)
No description
in
ManagesComponents at line 80
protected
createSlotContext()
No description
in
ManagesComponents at line 90
void
startComponentFirst(array $names, array $data = [])
Get the first view that actually exists from the given list, and start a component.
in
ManagesComponents at line 102
string
renderComponent()
Render the current component.
in
ManagesComponents at line 130
protected array
componentData()
Get the data for the given component.
in
ManagesComponents at line 155
mixed
getConsumableComponentData(string $key, mixed $default = null)
Get an item from the component data that exists above the current component.
in
ManagesComponents at line 186
void
slot(string $name, string|null $content = null, array $attributes = [])
Start the slot rendering process.
in
ManagesComponents at line 197
protected void
setSlotData(string $name, string|ComponentSlot|null $content)
No description
in
ManagesComponents at line 206
protected void
pushSlotStack(array $value)
No description
in
ManagesComponents at line 215
protected array
popSlotStack()
No description
in
ManagesComponents at line 229
void
endSlot()
Save the slot content for rendering.
in
ManagesComponents at line 244
protected int
currentComponent()
Get the index for the current component.
in
ManagesComponents at line 253
protected void
flushComponents()
Flush all of the component state.
in
ManagesEvents at line 19
array
creator(array|string $views, Closure|string $callback)
Register a view creator event.
Boot-only. The listener persists on the singleton View Factory's event dispatcher for the worker lifetime and affects every subsequent request.
in
ManagesEvents at line 36
array
composers(array $composers)
Register multiple view composers via an array.
Boot-only. The listeners persist on the singleton View Factory's event dispatcher for the worker lifetime and affect every subsequent request.
in
ManagesEvents at line 53
array
composer(array|string $views, Closure|string $callback)
Register a view composer event.
Boot-only. The listener persists on the singleton View Factory's event dispatcher for the worker lifetime and affects every subsequent request.
in
ManagesEvents at line 67
protected Closure|null
addViewEvent(string $view, Closure|string $callback, string $prefix = 'composing: ')
Add an event for a given view.
in
ManagesEvents at line 83
protected Closure
addClassEvent(string $view, string $class, string $prefix)
Register a class based view composer.
in
ManagesEvents at line 103
protected Closure
buildClassEventCallback(string $class, string $prefix)
Build a class based container callback Closure.
in
ManagesEvents at line 118
protected array
parseClassEvent(string $class, string $prefix)
Parse a class based composer name.
in
ManagesEvents at line 126
protected string
classEventMethodForPrefix(string $prefix)
Determine the class event method based on the given prefix.
in
ManagesEvents at line 134
protected void
addEventListener(string $name, Closure $callback)
Add a listener to the event dispatcher.
in
ManagesEvents at line 148
void
callComposer(View $view)
Call the composer for a given view.
in
ManagesEvents at line 158
void
callCreator(View $view)
Call the creator for a given view.
in
ManagesFragments at line 25
void
startFragment(string $fragment)
Start injecting content into a fragment.
in
ManagesFragments at line 32
protected void
pushFragmentStack(string $fragment)
No description
in
ManagesFragments at line 46
string
stopFragment()
Stop injecting content into a fragment.
in
ManagesFragments at line 67
mixed
getFragment(string $name, string|null $default = null)
Get the contents of a fragment.
in
ManagesFragments at line 75
array
getFragments()
Get the entire array of rendered fragments.
in
ManagesFragments at line 83
void
flushFragments()
Flush all of the fragments.
in
ManagesLayouts at line 32
void
startSection(string $section, string|View|null $content = null)
Start injecting content into a section.
in
ManagesLayouts at line 48
void
inject(string $section, string $content)
Inject inline content into a section.
in
ManagesLayouts at line 56
string
yieldSection()
Stop injecting content into a section and return its contents.
in
ManagesLayouts at line 72
string
stopSection(bool $overwrite = false)
Stop injecting content into a section.
in
ManagesLayouts at line 99
string
appendSection()
Stop injecting content into a section and append it.
in
ManagesLayouts at line 124
protected void
extendSection(string $section, string $content)
Append content to a given section.
in
ManagesLayouts at line 139
string
yieldContent(string $section, string|View $default = '')
Get the string contents of a section.
in
ManagesLayouts at line 160
string
getParentPlaceholder(string $section = '')
Get the parent placeholder for the current request.
in
ManagesLayouts at line 176
bool
hasSection(string $name)
Check if section exists.
in
ManagesLayouts at line 185
bool
sectionMissing(string $name)
Check if section does not exist.
in
ManagesLayouts at line 193
mixed
getSection(string $name, string|null $default = null)
Get the contents of a section.
in
ManagesLayouts at line 202
array
getSections()
Get the entire array of sections.
in
ManagesLayouts at line 210
void
flushSections()
Flush all of the sections.
in
ManagesLoops at line 21
void
addLoop(mixed $data)
Add new loop to the stack.
in
ManagesLoops at line 49
void
incrementLoopIndices()
Increment the top loop's indices.
in
ManagesLoops at line 70
void
popLoop()
Pop a loop from the top of the loop stack.
in
ManagesLoops at line 80
stdClass|null
getLastLoop()
Get an instance of the last loop in the stack.
in
ManagesLoops at line 92
array
getLoopStack()
Get the entire loop stack.
in
ManagesStacks at line 30
void
startPush(string $section, string $content = '')
Start injecting content into a push section.
in
ManagesStacks at line 41
protected void
pushStack(string $section)
No description
in
ManagesStacks at line 62
string
stopPush()
Stop injecting content into a push section.
in
ManagesStacks at line 78
protected void
extendPush(string $section, string $content)
Append content to a given push section.
in
ManagesStacks at line 100
void
startPrepend(string $section, string $content = '')
Start prepending content into a push section.
in
ManagesStacks at line 116
string
stopPrepend()
Stop prepending content into a push section.
in
ManagesStacks at line 132
protected void
extendPrepend(string $section, string $content)
Prepend content to a given stack.
in
ManagesStacks at line 154
string
yieldPushContent(string $section, string $default = '')
Get the string contents of a push section.
in
ManagesStacks at line 179
bool
isStackEmpty(string $section)
Determine if the given stack is empty.
in
ManagesStacks at line 190
void
flushStacks()
Flush all of the stacks.
in
ManagesTranslations at line 19
void
startTranslation(array $replacements = [])
Start a translation block.
in
ManagesTranslations at line 29
string
renderTranslation()
Render the current translation.
at line 89
__construct(EngineResolver $engines, ViewFinderInterface $finder, Dispatcher $events)
Create a new view factory instance.
at line 100
void
__clone()
Clone the factory for isolated render-time namespace changes.
at line 111
View
file(string $path, Arrayable|array $data = [], array $mergeData = [])
Get the evaluated view contents for the given view.
at line 123
View
make(string $view, Arrayable|array $data = [], array $mergeData = [])
Get the evaluated view contents for the given view.
at line 144
View
first(array $views, Arrayable|array $data = [], array $mergeData = [])
Get the first view that actually exists from the given list.
at line 160
string
renderWhen(bool $condition, string $view, Arrayable|array $data = [], array $mergeData = [])
Get the rendered content of the view based on a given condition.
at line 172
string
renderUnless(bool $condition, string $view, Arrayable|array $data = [], array $mergeData = [])
Get the rendered content of the view based on the negation of a given condition.
at line 180
string
renderEach(string $view, array $data, string $iterator, string $empty = 'raw|')
Get the rendered contents of a partial from a loop.
at line 211
protected string
normalizeName(string $name)
Normalize a view name.
at line 219
protected array
parseData(mixed $data)
Parse the given data into a raw array.
at line 227
protected View
viewInstance(string $view, string $path, Arrayable|array $data)
Create a new view instance from the given arguments.
at line 235
bool
exists(string $view)
Determine if a given view exists.
at line 251
Engine
getEngineFromPath(string $path)
Get the appropriate view engine for the given path.
at line 269
protected string|null
getExtension(string $path)
Get the extension used by the view file.
at line 284
mixed
share(array|string $key, mixed $value = null)
Add a piece of shared data to the environment.
Boot-only. Shared data persists on the singleton factory for the worker lifetime and is visible to every request handled by that worker.
at line 298
void
incrementRender()
Increment the rendering counter.
at line 308
void
decrementRender()
Decrement the rendering counter.
at line 322
void
observeRendering(callable $observer)
Register a pre-render observer.
Boot-only. The observer is called before each view's engine executes, receiving the View instance. Observers persist for the worker lifetime on this singleton.
at line 330
void
notifyRendering(View $view)
Notify pre-render observers that a view is about to render.
at line 340
protected int
getRenderCount()
Get the rendering counter.
at line 348
bool
doneRendering()
Check if there are no active render operations.
at line 356
bool
hasRenderedOnce(string $id)
Determine if the given once token has been rendered.
at line 366
void
markAsRenderedOnce(string $id)
Mark the given once token as having been rendered.
at line 382
void
addLocation(string $location)
Add a location to the array of view locations.
Boot-only. The location persists on the singleton view finder for the worker lifetime and affects every subsequent request.
at line 393
void
prependLocation(string $location)
Prepend a location to the array of view locations.
Boot-only. The location persists on the singleton view finder for the worker lifetime and affects every subsequent request.
at line 404
Factory
addNamespace(string $namespace, string|array $hints)
Add a new namespace to the loader.
Boot-only. The namespace persists on the singleton view finder for the worker lifetime and affects every subsequent request.
at line 417
Factory
prependNamespace(string $namespace, string|array $hints)
Prepend a new namespace to the loader.
Boot-only. The namespace persists on the singleton view finder for the worker lifetime and affects every subsequent request.
at line 430
Factory
replaceNamespace(string $namespace, string|array $hints)
Replace the namespace hints for the given namespace.
Boot-only. The namespace persists on the singleton view finder for the worker lifetime and affects every subsequent request.
at line 443
void
addExtension(string $extension, string $engine, Closure|null $resolver = null)
Register a valid view extension and its engine.
Boot-only. The extension persists on the singleton Factory and engine resolver for the worker lifetime and affects every subsequent request.
at line 461
void
flushState()
Flush all of the factory state like sections and stacks.
at line 475
void
flushStateIfDoneRendering()
Flush all of the section contents if done rendering.
at line 485
array
getExtensions()
Get the extension to engine bindings.
at line 493
EngineResolver
getEngineResolver()
Get the engine resolver instance.
at line 501
ViewFinderInterface
getFinder()
Get the view finder instance.
at line 513
void
setFinder(ViewFinderInterface $finder)
Set the view finder instance.
Boot or tests only. Swaps the finder on the singleton View Factory used by every coroutine; per-request use races and changes resolution for all concurrent renders.
at line 524
void
flushFinderCache()
Flush the cache of views located by the finder.
Boot or tests only. Clears the singleton finder's path cache shared across all coroutines.
at line 532
Dispatcher
getDispatcher()
Get the event dispatcher instance.
at line 544
void
setDispatcher(Dispatcher $events)
Set the event dispatcher instance.
Tests only. Swaps the dispatcher on the singleton View Factory used by every coroutine; per-request use races and breaks every concurrent view event.
at line 552
Container
getContainer()
Get the IoC container instance.
at line 564
void
setContainer(Container $container)
Set the IoC container instance.
Tests only. Swaps the container on the singleton View Factory used by every coroutine; per-request use races and breaks every concurrent view resolution.
at line 572
mixed
shared(string $key, mixed $default = null)
Get an item from the shared data.
at line 580
array
getShared()
Get all of the shared data for the environment.
at line 588
array
mergeSharedData(array $data)
Merge shared data into the given view data.