NaifyViewExtension\Dialect\Twig\TwigTemplateConverter クラス

TwigTemplateConverter — TwigのテンプレートをNaifyViewへ移す

変換できる構文をネイティブ構文または中間表現へ置き換える。 Twig本体とすべて同じ動作を保証するものではない。結果の診断情報も確認する。 通常の描画はTwigExtensionに任せ、移行時の確認や変換結果の保存にこのクラスを使う。

使用例

use NaifyViewExtension\NaifyViewExtension;
use NaifyViewExtension\Dialect\Twig\TwigTemplateConverter;

NaifyViewExtension::boot();
$converter = new TwigTemplateConverter();
$result = $converter->convert('<p>{{ name }}</p>', 'hello.twig');
if ($result->isComplete()) {
    echo $result->getNativeSource(); // 変換結果の確認。描画結果ではない。
}
// $result->getNotes()とgetUnsupported()で変換時の注意点を確認する。

プロパティ

名前型説明
private $notes array
private $unsupported array
private $localNames array
private $imports array alias => template
private $stringPlaceholders array
private $availableTemplateFiles array
private $templateSources array
private $dependencyTemplates array インライン展開したソースとその推移的依存
private $macroArguments array macro name => declared argument names
private $macroUsesVarargs array macro name => body reads Twig varargs
private $inlineIncludeSequence int
private $currentTemplateName ?string
private $extendsLayoutFile ?string
private $definesLayout bool
private $irBridge ExtensionIrConversionBridge
private $textHelper ExtensionConverterTextHelper
private $expressionSplitter ExtensionExpressionSplitter
private $metadataScanner TwigTemplateMetadataScanner
private $layoutBuilder ExtensionLayoutSurfaceBuilder
private $irBuilder ?TwigIrBuilder

メソッド

メソッド説明
public __construct(?ExtensionIrConversionBridge $irBridge, ?ExtensionConverterTextHelper $textHelper, ?ExtensionExpressionSplitter $expressionSplitter, ?TwigTemplateMetadataScanner $metadataScanner, ?ExtensionLayoutSurfaceBuilder $layoutBuilder):
public convert(string $twigSource, ?string $templateName, array $additionalLocalNames = '...', array $availableTemplateFiles = '...', array $templateSources = '...'): TwigTemplateConversionResult テンプレートをNaifyViewのネイティブ構文へ変換する
変換のたびに診断情報をリセットする。未対応の構文は結果のunsupportedで確認する。
public convertToIr(string $twigSource, ?string $templateName, array $additionalLocalNames = '...', array $availableTemplateFiles = '...', array $templateSources = '...'): TwigTemplateConversionResult 描画に渡せる中間表現を含めて変換する
直接変換できる構文はIRを作り、それ以外はネイティブ構文への変換を経由する。
継承など、他のテンプレートを必要とする構文にはプロジェクト情報も渡す。
private hasDirectIrBlockingSurface(string $source): bool
private getIrBuilder(): TwigIrBuilder
private readExtendsFile(string $source): ?string
private convertComments(string $source): string
private inlineImports(string $source): string
private convertBlocks(string $source): string
private convertForElseBlocks(string $source): string
private convertForTag(string $left, string $iterable): string
private isolateConvertedMacroBodies(string $source): string
private injectLoopParentIndexWorkaround(string $source): string
private convertInterpolations(string $source): string
private convertIncludeExpressionToOutput(string $expression): ?string
private convertIncludeExpressionToCapture(string $name, string $expression): ?string
private parseIncludeCall(string $expression): ?array
private applyFiltersToNativeValue(string $valueName, array $filters): string
private convertFilteredExpression(string $expression): string
private convertArrowFilterCall(string $native, string $rawFilter): ?string
private convertFilterCall(string $rawFilter): string
private convertTwigTests(string $expression): string
private convertExpression(string $expression): string
private convertTwigLoopIndexExpression(string $expression): string
private convertHelperWrapNamedArguments(string $expr): ?string
private packMacroVarargs(string $expr): string
private convertStringInterpolation(string $expression): string
private splitTopLevel(string $source, string $separator): array
private extractStringLiterals(string $expr): string
private restoreStringLiterals(string $expr): string
private observeUnsupportedTwigSurface(string $source): void
private markUnsupportedFilter(string $name): string
private buildInlineIncludeNative(string $templateExpression, string $withExpression, bool $isolated): ?string
private recordInlineDependencies(string $template, TwigTemplateConversionResult $result): void
private canInlineStaticInclude(string $templateExpression): bool
private isSafeStaticInlineIncludeSource(string $source): bool
private resolveTwigIncludeExpression(string $expression): string
private parseTwigObjectLiteral(string $expression): array
private renameConvertedLocal(string $source, string $from, string $to): string
private resolveIncludePath(string $includeFile): string
private normalizePath(string $path): string
private normalizeName(string $value, string $fallback): string
private escapeAttribute(string $value): string
private escapeText(string $value): string
private quoteNativeString(string $value): string