NaifyView\View\ViewConfigurator クラス
ViewConfigurator — Viewの生成条件をメソッドチェーンで組み立てる
探索先や描画設定を積み、NaifyView::create()へ渡すための入口。 生成後に設定を変えても、すでに作ったViewの設定は変わらない。 NaifyView::configure()は共有設定を返すため、用途ごとに分ける場合は直接生成する。
使用例
use NaifyView\NaifyView;
use NaifyView\View\ViewConfigurator;
NaifyView::boot();
$config = (new ViewConfigurator(__DIR__ . '/views'))
->setCacheDir(__DIR__ . '/cache/views')
->setAutoEscape(true);
$view = NaifyView::create($config);
echo $view->render('hello.html', ['name' => 'Naify']);
プロパティ
| 名前 | 型 | 説明 |
|---|---|---|
private
$config
|
ViewConfig |
このconfiguratorで編集中の設定 |
メソッド
| メソッド | 説明 |
|---|---|
public
__construct(array|string|null $viewsDir):
|
探索先を指定して、独立したView設定を作る |
public
reset(): static
|
探索先や拡張も含め、この設定を初期状態に戻す
reset()の前に登録した探索先も消える。登録し直す場合はreset()の後に追加する。 生成済みのViewは変更しない。 |
public
getConfig(): ViewConfig
|
編集中の設定を直接扱うために返す
コピーではないので、返された設定への変更もこのconfiguratorに反映される。 分離した設定が必要な場合はsnapshotConfig()を使う。 |
public
addTemplateDir(string $templateDir): static
|
探索先を末尾に追加する |
public
addTemplateDirs(array $templateDirs): static
|
指定された順序で探索先を追加する |
public
setCacheDir(?string $cacheDir): static
|
コンパイル済みPHPの保存先を設定する
nullで指定を解除する。描画には書き込み可能な保存先が必要。 |
public
setParserDialect(?string $parserDialect): static
|
テンプレートを解析する方言名を設定する
外部方言を使う場合は、対応する拡張も登録する。 |
public
setErrorHandler(?callable $errorHandler): static
|
描画失敗時の通知先を設定する
例外と診断情報の配列を受け取る。戻り値で描画結果を置き換えるものではない。 |
public
setForceCompile(bool $forceCompile): static
|
キャッシュがあっても再コンパイルするかを設定する
テンプレートの変更を確認する開発時に使う。 |
public
setExecutionTimeLimit(int $seconds): static
|
描画時に適用する実行時間の上限(秒)を設定する
1未満は1に補正する。 |
public
setTemplateRecursionLimit(int $limit): static
|
テンプレート呼び出しの再帰上限を設定する
1未満は1に補正する。 |
public
setCompileLevel(string $compileLevel): static
|
生成コードの診断レベルを設定する
production / debug / devを指定する。認識できない値はdebugになる。 |
public
setCompilePipeline(string $compilePipeline): static
|
コンパイル経路を設定する
directは直接コンパイル、irは中間表現を経由する。認識できない値はdirectになる。 |
public
setTraceLevel(?string $traceLevel): static
|
描画トレースの詳しさを設定する
off / summary / detail / debugを指定する。nullは明示指定なし、認識できない値はoffになる。 |
public
useProfiler(mixed $levelInput = debug, bool $hostProfilerEnabled = true): static
|
NaifyView profiler level を configurator から指定する
NaifyView 自体の profiler を設定し、Naify が起動している request では bridge 経由で Naify::profiler() へ観測点を流せる状態にする。 |
public
setAutoEscape(bool $autoEscape): static
|
式の出力を自動でHTMLエスケープするかを設定する
HTMLとして表示する通常の変数にはtrueを指定する。 |
public
setDelimiters(?array $delimiters): static
|
式を囲む区切り文字の設定を設定する
nullなら標準の区切り文字を使う。 |
public
setCompileDirectivePrefix(?string $directivePrefix): static
|
コンパイル指示の接頭辞を設定する
nullなら標準の接頭辞を使う。 |
public
setCompilePrologMarkers(?array $prologMarkers): static
|
テンプレート先頭で認識する宣言マーカーを設定する
nullなら標準のマーカーを使う。 |
public
setTemplateBasePath(?string $templateBasePath): static
|
相対テンプレート名を解決する基準パスを設定する |
public
setTemplate(?string $template): static
|
描画時に省略できる既定テンプレート名を設定する
nullで既定の指定を解除する。 |
public
addFilterHandler(object|array $filterHandler): static
|
式のフィルターを提供する処理を追加する |
public
clearFilterHandlers(): static
|
登録済みのフィルター提供元をすべて外す
関数や中間表現の提供元は残す。 |
public
addCallableProvider(object $callableProvider): static
|
テンプレートから呼べる関数の提供元を追加する |
public
addTemplateIrProvider(TemplateIrProviderInterface $templateIrProvider): static
|
テンプレートを中間表現へ変換する提供元を追加する |
public
addExtension(NaifyViewExtensionInterface $extension): static
|
拡張に含まれるフィルター・関数・変換処理をまとめて登録する |
public
snapshotConfig(): ViewConfig
|
View生成に渡すため、現在の設定を複製する
設定内のオブジェクトまで再帰的に複製する処理ではない。 |