Documentation

LegacyViewConverter
in package

Converts a legacy ZubZet view/layout (the "return type" syntax) into a Katana .blade.php document, as part of the 1.3.0 upgrade.

Views become template-inheritance children. The old "body" closure turns into @section("content"), an optional "head" closure into @section("head"), and the file @extends the layout picked at render time:

Tags
extends

($layout) @section("head") ... @endsection @section("content") ... @endsection

$layout is supplied as render data (the dotted view name of the chosen layout, e.g. "layout.default_layout" or "rendering.mail_layout"), so the same view works whether the layout is the default, chosen per request, passed explicitly, or lives outside the layout/ directory.

Layouts become the parents: the $body($opt) / $head($opt) closure calls turn into @yield("content") / @yield("head"); everything else (including the $opt["layout_essentials_*"] calls) stays raw PHP and is dedented to column 0.

Raw PHP ( and ) is preserved verbatim; Katana keeps it out of the Blade compiler. Literal Blade markers ({{, {!!, {{--) are escaped, but only where they appear in template HTML: inside raw PHP Katana already leaves them untouched, so escaping there would emit a stray "@".

Extraction is tokenizer-based (token_get_all) so it is robust against braces, open/close-tag boundaries and nested control structures inside the closures.

Table of Contents

convertFile()  : string
Convert any legacy view or layout. Returns the .blade.php document.
convertLayout()  : string
A legacy layout -> the parent template with @yield placeholders.
convertView()  : string
A legacy view -> an @extends child with head/content sections.
extractSections()  : array<string|int, mixed>
isLayout()  : bool
True when the source is a legacy layout (returns a "layout" closure).
isLegacyView()  : bool
True when the source looks like a legacy return[...] view/layout at all.
neutralize()  : string
Escape literal Blade markers so Katana emits them verbatim, but only in template HTML (T_INLINE_HTML). Markers inside raw PHP are already safe.
dedent()  : string
Remove the common leading indentation (the wrapper closure's indent) so a dedented document sits at column 0. A first line left inline with the opening ?> tag has a smaller indent than the block and is treated as an outlier so it does not shrink the common indent to remove.
describe()  : string
detokenizeTemplate()  : string
Reconstruct template text from closure-body tokens, stripping the wrapping tags.
escapeMarkers()  : string
essentialsTags()  : string
Replace the framework's layout-essentials closure calls with the Blade components the framework provides for them (resolved via a shared anonymous-component path), so a layout carries no raw essentials PHP.
extractClosure()  : array<string|int, mixed>
section()  : string
Section body: keep its indentation (it nests under @section), trim blank edges.
yieldCall()  : string
Replace a call to a layout closure param (`<?= $body($opt) ?>`, the "echo" form or a bare statement form) with the matching @yield.

Methods

convertFile()

Convert any legacy view or layout. Returns the .blade.php document.

public static convertFile(string $source) : string
Parameters
$source : string
Tags
throws
RuntimeException

when the source is not a convertible legacy view.

Return values
string —

convertLayout()

A legacy layout -> the parent template with @yield placeholders.

public static convertLayout(string $source) : string
Parameters
$source : string
Return values
string —

convertView()

A legacy view -> an @extends child with head/content sections.

public static convertView(string $source) : string
Parameters
$source : string
Return values
string —

extractSections()

public static extractSections(string $source) : array<string|int, mixed>
Parameters
$source : string
Return values
array<string|int, mixed> —

isLayout()

True when the source is a legacy layout (returns a "layout" closure).

public static isLayout(string $source) : bool
Parameters
$source : string
Return values
bool —

isLegacyView()

True when the source looks like a legacy return[...] view/layout at all.

public static isLegacyView(string $source) : bool
Parameters
$source : string
Return values
bool —

neutralize()

Escape literal Blade markers so Katana emits them verbatim, but only in template HTML (T_INLINE_HTML). Markers inside raw PHP are already safe.

public static neutralize(string $tpl) : string

{{-- .. --}} -> wrapped in @verbatim (the @{{-- escape does not work because comments are stripped before echo-escaping) {!! .. !!} -> @{!! .. !!} {{ .. }} -> @{{ .. }}

Parameters
$tpl : string
Return values
string —

dedent()

Remove the common leading indentation (the wrapper closure's indent) so a dedented document sits at column 0. A first line left inline with the opening ?> tag has a smaller indent than the block and is treated as an outlier so it does not shrink the common indent to remove.

private static dedent(string $content) : string
Parameters
$content : string
Return values
string —

describe()

private static describe(mixed $t) : string
Parameters
$t : mixed
Return values
string —

detokenizeTemplate()

Reconstruct template text from closure-body tokens, stripping the wrapping tags.

private static detokenizeTemplate(array<string|int, mixed> $bodyTokens) : string
Parameters
$bodyTokens : array<string|int, mixed>
Return values
string —

escapeMarkers()

private static escapeMarkers(string $html) : string
Parameters
$html : string
Return values
string —

essentialsTags()

Replace the framework's layout-essentials closure calls with the Blade components the framework provides for them (resolved via a shared anonymous-component path), so a layout carries no raw essentials PHP.

private static essentialsTags(string $tpl) : string

The components sit under the framework's own "zubzet" component namespace so an app component cannot shadow them by accident. $opt"layout_essentials_head" -> <x-zubzet::head :opt="$opt"/> $opt"layout_essentials_body" -> <x-zubzet::body :opt="$opt"/>

Parameters
$tpl : string
Return values
string —

extractClosure()

private static extractClosure(string $source, string $key) : array<string|int, mixed>
Parameters
$source : string
$key : string
Return values
array<string|int, mixed> —

section()

Section body: keep its indentation (it nests under @section), trim blank edges.

private static section(string $content) : string
Parameters
$content : string
Return values
string —

yieldCall()

Replace a call to a layout closure param (`<?= $body($opt) ?>`, the "echo" form or a bare statement form) with the matching @yield.

private static yieldCall(string $tpl, string|null $var, string $section) : string
Parameters
$tpl : string
$var : string|null
$section : string
Return values
string —

Search results