NaifyViewExtension\Dialect\Smarty\SmartyTemplateConverter クラス
SmartyTemplateConverter — SmartyのテンプレートをNaifyViewへ移す
変換できる構文をネイティブ構文または中間表現へ置き換える。 Smarty本体とすべて同じ動作を保証するものではない。結果の診断情報も確認する。 通常の描画はSmartyExtensionに任せ、移行時の確認や変換結果の保存にこのクラスを使う。
使用例
use NaifyViewExtension\NaifyViewExtension;
use NaifyViewExtension\Dialect\Smarty\SmartyTemplateConverter;
NaifyViewExtension::boot();
$converter = new SmartyTemplateConverter();
$result = $converter->convert('<p>{$name}</p>', 'hello.tpl');
if ($result->isComplete()) {
echo $result->getNativeSource(); // 変換結果の確認。描画結果ではない。
}
// $result->getNotes()とgetUnsupported()で変換時の注意点を確認する。
プロパティ
| 名前 | 型 | 説明 |
|---|---|---|
private
$notes
|
array |
|
private
$unsupported
|
array |
|
private
$dependencyTemplates
|
array |
Sources actually consulted while building this result. |
private
$localNames
|
array |
|
private
$loopItemMetadata
|
array |
|
private
$loopMetadataNames
|
array |
|
private
$sectionNames
|
array |
|
private
$literalPlaceholders
|
array |
|
private
$availableTemplateFiles
|
array |
|
private
$templateSources
|
array |
|
private
$scopeLeakingTemplateFiles
|
array |
|
private
$inlineStack
|
array |
|
private
$foreachAfterSetStack
|
array |
|
private
$foreachAfterMetadataNames
|
array |
loops/items that need after-loop show/total metadata |
private
$captureAppendBufferNames
|
array |
|
private
$inlineIncludeSequence
|
int |
|
private
$currentTemplateName
|
?string |
|
private
$extendsLayoutFile
|
?string |
|
private
$definesLayout
|
bool |
|
private
$irBridge
|
ExtensionIrConversionBridge |
|
private
$textHelper
|
ExtensionConverterTextHelper |
|
private
$attributeReader
|
SmartyAttributeReader |
|
private
$metadataScanner
|
SmartyTemplateMetadataScanner |
|
private
$layoutBuilder
|
ExtensionLayoutSurfaceBuilder |
|
private
$foreachSpecParser
|
SmartyForeachSpecParser |
|
private
$irBuilder
|
?SmartyIrBuilder |
メソッド
| メソッド | 説明 |
|---|---|
public
__construct(?ExtensionIrConversionBridge $irBridge, ?ExtensionConverterTextHelper $textHelper, ?SmartyAttributeReader $attributeReader, ?SmartyTemplateMetadataScanner $metadataScanner, ?ExtensionLayoutSurfaceBuilder $layoutBuilder, ?SmartyForeachSpecParser $foreachSpecParser):
|
|
public
convert(string $smartySource, ?string $templateName, array $additionalLocalNames = '...', array $availableTemplateFiles = '...', array $templateSources = '...', array $scopeLeakingTemplateFiles = '...', array $inlineStack = '...', bool $stripSmartyScopeMarkers = true): SmartyTemplateConversionResult
|
テンプレートをNaifyViewのネイティブ構文へ変換する
変換のたびに診断情報をリセットする。未対応の構文は結果のunsupportedで確認する。 |
public
convertToIr(string $smartySource, ?string $templateName, array $additionalLocalNames = '...', array $availableTemplateFiles = '...', array $templateSources = '...', array $scopeLeakingTemplateFiles = '...', array $inlineStack = '...'): SmartyTemplateConversionResult
|
描画に渡せる中間表現を含めて変換する
直接変換できる構文はIRを作り、それ以外はネイティブ構文への変換を経由する。 継承など、他のテンプレートを必要とする構文にはプロジェクト情報も渡す。 |
private
hasDirectIrBlockingSurface(string $source): bool
|
|
private
prepareDirectIrSource(string $source, ?string $templateName, array $templateSources, array $scopeLeakingTemplateFiles, string $directIrSource): bool
|
direct IR で include を扱うのは、scope を変えない静的 include だけに限定する。 |
private
expandDirectIrIncludes(string $source, ?string $templateName, array $templateSources, array $scopeLeakingTemplateFiles, array $seenTemplateFiles): ?string
|
|
private
getIrBuilder(): SmartyIrBuilder
|
|
private
readExtendsFile(string $source): ?string
|
|
private
extractLiteralBlocks(string $source): string
|
|
private
restoreLiteralBlocks(string $source): string
|
|
private
convertComments(string $source): string
|
|
private
convertBlocks(string $source): string
|
|
private
convertCaptureBlocks(string $source): string
|
|
private
convertNestedVariableInterpolations(string $source): string
|
|
private
buildSmartyBodyExpression(string $body): string
|
|
private
convertAssignTag(string $attributes): string
|
|
private
convertAppendTag(string $attributes): string
|
|
private
convertCaptureTag(string $attributes): string
|
|
private
buildSmartyCaptureVariableName(string $name): string
|
|
private
convertInlineIfs(string $source): string
|
|
private
convertMixedAttributeInterpolations(string $source): string
|
|
private
convertSectionBlocks(string $source): string
|
|
private
buildSectionLoopOpen(array $spec): string
|
|
private
buildSectionAfterSet(array $spec): string
|
|
private
buildSectionFilterExpression(array $spec, string $filterName): string
|
|
private
convertIncludeTag(string $attributesSource): string
|
|
private
buildInlineIncludeElement(string $file, array $attributes, string $scope): string
|
|
private
shouldInlineInclude(string $file, string $scope, array $attributes): bool
|
Static include のうち、scope 差分を壊しにくいものだけ変換時に畳む。
Runtime include は template state / derived context を作るため、細かい fragment が多い 互換ページでは効きやすい。代入や layout/block を含む fragment は意味が変わりやすいので、 既存の scope-leaking 判定か明示 scope 以外では inline しない。 |
private
isSafeStaticInlineIncludeSource(string $source): bool
|
|
private
renameConvertedLocal(string $source, string $from, string $to): string
|
|
private
hasRootScopeAssign(string $source): bool
|
|
private
protectRootScopeAssignTags(string $source, array $protectedTags): string
|
|
private
stripSmartyScopeMarkers(string $source): string
|
|
private
resolveIncludePath(string $file): string
|
|
private
resolveIncludePathFor(string $file, ?string $templateName): string
|
|
private
buildIncludeElement(string $file, array $attributes): string
|
|
private
buildDynamicIncludeElement(string $fileExpression, array $attributes): string
|
|
private
isDynamicIncludeToken(string $fileToken): bool
|
|
private
convertForeachTag(string $attributes): string
|
|
private
buildForeachAfterBufferName(string $loopName): string
|
|
private
buildForeachBeforeSet(string $afterBufferName): string
|
|
private
buildForeachTickSet(string $afterBufferName): string
|
|
private
buildForeachAfterSet(string $loopName, string $afterBufferName): string
|
|
private
convertForeachElseBlocks(string $source): string
|
|
private
convertInterpolations(string $source): string
|
|
private
looksLikeJsonObjectMember(string $expression): bool
|
|
private
convertFunctionCallTag(string $source): string
|
|
private
convertFilteredExpression(string $expression): string
|
|
private
convertFilterCall(string $rawFilter): string
|
|
private
markUnsupportedFilter(string $name): string
|
|
private
convertFilterArgument(string $argument): string
|
|
private
convertExpression(string $expression): string
|
|
private
convertSmartyItemMetadata(string $expression): string
|
|
private
normalizeDynamicDotPath(string $expression): string
|
|
private
normalizeSimpleCallArguments(string $expression): string
|
|
private
convertFilteredSubExpressions(string $expression): string
|
|
private
readSmartyAttribute(string $source, string $name): string
|
|
private
readSmartyAttributeToken(string $source, string $name): string
|
|
private
readSmartyPositionalToken(string $source): string
|
|
private
readSmartyAttributeTokens(string $source): array
|
|
private
readSmartyAttributes(string $source): array
|
|
private
parseForeachSpec(string $attributes): array
|
|
private
parseSectionSpec(string $attributes): array
|
|
private
convertSmartyValueToken(string $token): string
|
|
private
convertSmartyStringInterpolation(string $value): string
|
|
private
replaceSmartyOpeningTags(string $source, string $tagName, callable $callback): string
|
Smarty tag の attribute 中には `{$...}` が入るため、単純な `[^}]` regex では閉じ位置を誤る。Extension 内の小さな scanner で tag だけを置換する。 |
private
findSmartyTagEnd(string $source, int $offset): ?int
|
|
private
observeUnsupportedSmartySurface(string $source): void
|
|
private
normalizeName(string $value, string $fallback): string
|
|
private
escapeAttribute(string $value): string
|
|
private
escapeText(string $value): string
|
|
private
quoteNativeString(string $value): string
|