NaifyView\Compiler\CompiledClassArtifactCompiler クラス

CompiledClassArtifactCompiler — AST を generated PHP class へ落とす compiler

Naify parser が作った AST を、OPcache に載せやすい PHP class artifact へ変換する。 unsupported syntax は fallback せず、compile error として観測できる形で止める。

使用例

$compiler = new CompiledClassArtifactCompiler(cacheDir: __DIR__ . '/cache');
$artifact = $compiler->compileTemplateArtifact('index.html', __DIR__ . '/views/index.html');

プロパティ

名前型説明
private $parser NaifyParser dialect parser
private $expressionEvaluator NaifyExpressionEvaluator compile-time expression splitter
private $bindingParser NaifyBindingParser compile-time with-binding parser
private $helperChainParser NaifyHelperChainParser explicit filter world parser
private $runtime CompiledTemplateRuntime generated class runtime ABI
private $dependencyPlanner CompiledArtifactDependencyPlanner compile-time dependency planner
private $cacheStore CompiledArtifactCacheStore compiled artifact cache filesystem owner
private $cacheProbe CompiledArtifactCacheProbe warm-hit descriptor / freshness owner
private $classSourceBuilder CompiledGeneratedClassSourceBuilder generated class source shell owner
private $templateMethodRegistry CompiledTemplateMethodRegistry generated template/macro method registry owner
private $compileSession CompiledClassCompileSession current compile cycle mutable state owner
private $cacheDir ?string cache root
private $compileLevel string generated PHP readability / exposure level
private $templateRecursionLimit int generated class template recursion limit contract
private $templatePathResolver CompiledTemplatePathResolver include/layout resolution owner
private $sourceMetadataBuilder CompiledGeneratedSourceMetadataBuilder generated source metadata owner
private $dependencyPlanBuilder CompiledDependencyPlanBuilder dependency plan / preflight metadata owner
private $expressionFastPathBuilder CompiledExpressionFastPathBuilder trivial expression lowering owner
private $elementSourceBuilder CompiledElementSourceBuilder element / attribute source owner
private $outputChunkBuilder CompiledOutputChunkBuilder output append chunk/coalesce owner
private $loopSourceBuilder CompiledLoopSourceBuilder foreach / range source owner
private $ifSourceBuilder CompiledIfSourceBuilder if / elseif / else source owner
private $templateCompositionSourceBuilder CompiledTemplateCompositionSourceBuilder include / layout / block / slot source owner
private $templateSurfacePreflight TemplateSurfacePreflight cheap compile routing owner
private $templateSurfaceDocumentBuilder CompiledTemplateSurfaceDocumentBuilder static/interpolation-only document owner

メソッド

メソッド説明
public __construct(?NaifyParser $parser, ?string $cacheDir, ?CompiledTemplateRuntime $runtime, ?CompiledArtifactDependencyPlanner $dependencyPlanner, ?CompiledArtifactCacheStore $cacheStore, ?NaifyExpressionEvaluator $expressionEvaluator, array $filterHandlers = '...', array $callableProviders = '...', array $templateRoots = '...', string $interpolationOpen = {{, string $interpolationClose = }}, string $directivePrefix = nf-, ?array $prologMarkers, string $compileLevel = debug, bool $autoEscape = false, int $templateRecursionLimit = 8): void インスタンスを初期化する
public setCacheDir(?string $cacheDir): void `setCacheDir()` の値を設定する
public getCacheDir(): ?string `getCacheDir()` の値を返す
public getCompilerVersion(): string `getCompilerVersion()` の値を返す
public getCompileLevel(): string `getCompileLevel()` の値を返す
public getCacheFamily(): string `getCacheFamily()` の値を返す
public probeTemplateArtifactCache(string $template, string $resolvedPath, string $mode = naify-compiled-class): array `probeTemplateArtifactCache()` を実行する
private readMetaDependencyFreshnessHash(?array $cachedMeta): ?string meta から dependency freshness hash を取り出す(identity 再構築用)
public compileTemplateArtifact(string $template, string $resolvedPath, string $mode = naify-compiled-class, bool $forceCompile = false): CompiledClassArtifact `compileTemplateArtifact()` を実行する
public compileDocumentArtifact(string $template, string $resolvedPath, string $templateSource, DocumentNode $document, string $mode = naify-compiled-class, string $compileSurface = full-native, array $dependencyPlanOverrides = '...', bool $forceCompile = false, array $dependencyPaths = '...'): CompiledClassArtifact `compileDocumentArtifact()` を実行する
public tryCreateWarmHitArtifact(string $template, string $resolvedPath, string $mode): ?CompiledClassArtifact 有効なキャッシュだけを取得し、miss時はコンパイルせずnullを返す。
private buildCompiledDisplayPathMap(array $templatePaths): array
private buildCompiledClassSource(array $cacheDescriptor, string $resolvedPath, string $templateSource, DocumentNode $document, string $mode, array $dependencyPlan, string $compileSurface = full-native, array $dependencyFreshnessResolvedPaths = '...', array $dependencyFreshnessSignatures = '...', string $runtimeClassName = , string $runtimeClassFilePath = , string $runtimeClassFileKey = , array $dependencyPaths = '...'): string `buildCompiledClassSource()` を実行する
依存解析で dependency freshness hash が確定した後に runtime class identity を確定し、
その class 名で source を生成する。確定した identity は by-ref で呼び出し側へ返す。
public getSourceParser(): NaifyParser Internal pipeline assembly: retain the same source syntax for direct and IR compilation.
public getTemplateSurfacePreflight(): TemplateSurfacePreflight Internal pipeline assembly: the surface classifier shares the configured delimiters.
private compileNodeList(array $nodes, string $scopeVar, string $outputVar, int $indentLevel, int $counter, int $loopDepth, string $stateVar, string $slotOverridesVar, string $currentTemplatePath, array $compiledTemplates): array `compileNodeList()` を実行する
private compileInterpolationNode(InterpolationNode $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, string $stateVar, string $currentTemplatePath): array `compileInterpolationNode()` を実行する
private compileNode(NodeInterface $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, int $loopDepth, string $stateVar, string $slotOverridesVar, string $currentTemplatePath, array $compiledTemplates): array `compileNode()` を実行する
private compileSetNode(SetNode $node, string $scopeVar, int $indentLevel): array `compileSetNode()` を実行する
private compileCaptureNode(CaptureNode $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, int $loopDepth, string $stateVar, string $slotOverridesVar, string $currentTemplatePath, array $compiledTemplates): array `compileCaptureNode()` を実行する
private buildEvaluatedArgumentListExpression(string $argumentExpression, string $scopeVar): string `buildEvaluatedArgumentListExpression()` を実行する
private compileElementNode(ElementNode $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, int $loopDepth, string $stateVar, string $slotOverridesVar, string $currentTemplatePath, array $compiledTemplates): array `compileElementNode()` を実行する
private compileIfNode(IfNode $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, int $loopDepth, string $stateVar, string $slotOverridesVar, string $currentTemplatePath, array $compiledTemplates): array `compileIfNode()` を実行する
private compileForEachNode(ForEachNode $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, int $loopDepth, string $stateVar, string $slotOverridesVar, string $currentTemplatePath, array $compiledTemplates): array `compileForEachNode()` を実行する
private compileForRangeNode(ForRangeNode $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, int $loopDepth, string $stateVar, string $slotOverridesVar, string $currentTemplatePath, array $compiledTemplates): array `compileForRangeNode()` を実行する
private wrapLoopScopeLines(array $lines, string $scopeVar, string $parentScopeVar, string $parentTokenVar, string $indent): array One local scope per loop; explicit parent writes survive every exit path.
private nodeListContainsLoopControl(array $nodes): bool ループ本体に break / continue があるかを調べる
private nodeContainsLoopControl(NodeInterface $node): bool `nodeContainsLoopControl()` を実行する
private compileLoopControlNode(NodeInterface $node, string $keyword, int $indentLevel, int $loopDepth): array `compileLoopControlNode()` を実行する
private compileIncludeNode(IncludeNode $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, string $stateVar, string $currentTemplatePath, array $compiledTemplates): array `compileIncludeNode()` を実行する
private compileLayoutNode(LayoutNode $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, int $loopDepth, string $stateVar, string $currentTemplatePath, array $compiledTemplates): array `compileLayoutNode()` を実行する
private compileSlotNode(SlotNode $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, int $loopDepth, string $stateVar, string $slotOverridesVar, string $currentTemplatePath, array $compiledTemplates): array `compileSlotNode()` を実行する
private compileBlockNode(BlockNode $node, string $scopeVar, string $outputVar, int $indentLevel, int $counter, int $loopDepth, string $stateVar, string $slotOverridesVar, string $currentTemplatePath, array $compiledTemplates): array `compileBlockNode()` を実行する
private buildUnsupportedNodeException(NodeInterface $node, string $reason): NaifyViewException `buildUnsupportedNodeException()` を実行する
private indent(int $level): string `indent()` を実行する
private resolveCompiledMacroCall(string $expression, string $currentTemplatePath): ?array `resolveCompiledMacroCall()` を実行する
private resolveCompiledMacroFilteredCall(string $expression, string $currentTemplatePath): ?array `resolveCompiledMacroFilteredCall()` を実行する
private normalizeCompileLevel(string $compileLevel): string `normalizeCompileLevel()` を実行する