Helper
in package
Table of Contents
Constants
- OPT_OUT_ATTR_CONTENT = '/\bcontent\s*=\s*(?:"disable"|\'disable\'|disable(?=[\s\/>]))/i'
- OPT_OUT_ATTR_NAME = '/\bname\s*=\s*(?:"acms-htmx"|\'acms-htmx\'|acms-htmx(?=[\s\/>]))/i'
- OPT_OUT_META_TAG = '/<meta\b[^>]*>/i'
- ページ単位のオプトアウト宣言 <meta name="acms-htmx" content="disable"> の検出パターン。 属性順の入れ替えに対応するため、meta タグを抽出したうえで name / content を個別に照合する。
- TEMPLATE_CONFIG_CONTENT = '/\bcontent\s*=\s*(?:"([^"]*)"|\'([^\']*)\'|([^\s\/>]+))/i'
- TEMPLATE_CONFIG_META = '/<meta\b[^>]*\bname\s*=\s*(?:"htmx-config"|\'htmx-config\'|htmx-config(?=[\s\/>]))[^>]*>/i'
- テンプレートに書かれた meta[name="htmx-config"] の検出パターン。
Methods
- buildConfig() : array<string, mixed>
- config() : array<string, mixed>
- emitPushUrlHeader() : void
- extractTemplateConfig() : array<string, mixed>
- テンプレートに書かれた meta[name="htmx-config"] の content を連想配列として取り出す。
- resolvePushUrlHeader() : string|null
- rewriteTemplateConfigMeta() : string|null
- テンプレートの meta[name="htmx-config"] の content をマージ済みの設定へ書き換える。
- shouldInjectOptOutMeta() : bool
- オプトアウト宣言 <meta name="acms-htmx" content="disable"> をサーバー側で注入するか判定する。
- shouldLoadHtmxStatically() : bool
- DOM解析ではなく部分文字列で判定する。誤検出時のコストが「htmxを余分に読み込む」だけで 無害な一方、全リクエストで走る軽量な真偽判定にDOMDocumentは不釣り合いに重いため。
- dispatchConfigHook() : void
- findTemplateConfigContent() : string|null
- isOptedOut() : bool
- marks() : array<string|int, string>
- replaceContentAttribute() : string
Constants
OPT_OUT_ATTR_CONTENT
private
mixed
OPT_OUT_ATTR_CONTENT
= '/\bcontent\s*=\s*(?:"disable"|\'disable\'|disable(?=[\s\/>]))/i'
OPT_OUT_ATTR_NAME
private
mixed
OPT_OUT_ATTR_NAME
= '/\bname\s*=\s*(?:"acms-htmx"|\'acms-htmx\'|acms-htmx(?=[\s\/>]))/i'
OPT_OUT_META_TAG
ページ単位のオプトアウト宣言 <meta name="acms-htmx" content="disable"> の検出パターン。 属性順の入れ替えに対応するため、meta タグを抽出したうえで name / content を個別に照合する。
private
mixed
OPT_OUT_META_TAG
= '/<meta\b[^>]*>/i'
TEMPLATE_CONFIG_CONTENT
private
mixed
TEMPLATE_CONFIG_CONTENT
= '/\bcontent\s*=\s*(?:"([^"]*)"|\'([^\']*)\'|([^\s\/>]+))/i'
TEMPLATE_CONFIG_META
テンプレートに書かれた meta[name="htmx-config"] の検出パターン。
private
mixed
TEMPLATE_CONFIG_META
= '/<meta\b[^>]*\bname\s*=\s*(?:"htmx-config"|\'htmx-config\'|htmx-config(?=[\s\/>]))[^>]*>/i'
Methods
buildConfig()
public
buildConfig(string $json[, array<string, mixed> $templateConfig = [] ]) : array<string, mixed>
Parameters
- $json : string
-
config('htmx_config', '}') の値
- $templateConfig : array<string, mixed> = []
-
テンプレートの meta[name="htmx-config"] の内容
Return values
array<string, mixed>config()
public
config([string $html = '' ]) : array<string, mixed>
Parameters
- $html : string = ''
-
レンダリング済みの出力 HTML(テンプレート側の設定を取り込むために渡す)
Return values
array<string, mixed>emitPushUrlHeader()
public
emitPushUrlHeader(string $tpl) : void
Parameters
- $tpl : string
-
レンダリング済みの出力 HTML
extractTemplateConfig()
テンプレートに書かれた meta[name="htmx-config"] の content を連想配列として取り出す。
public
extractTemplateConfig(string $html) : array<string, mixed>
htmx 本体は meta を querySelector で 1 件だけ読むため、こちらも先頭の 1 件のみを対象にする。
Parameters
- $html : string
-
レンダリング済みの出力 HTML
Return values
array<string, mixed> —meta が無い・content が不正な JSON の場合は空配列
resolvePushUrlHeader()
public
resolvePushUrlHeader(string $tpl) : string|null
Parameters
- $tpl : string
-
レンダリング済みの出力 HTML
Return values
string|nullrewriteTemplateConfigMeta()
テンプレートの meta[name="htmx-config"] の content をマージ済みの設定へ書き換える。
public
rewriteTemplateConfigMeta(string $html, array<string, mixed> $config) : string|null
差し替えではなく書き換えなのは、htmx が先頭の meta しか読まないため。コア側が別途 meta を 追加しても、テンプレート側の meta が先に現れる限りサーバーの設定(allowEval の false 強制を 含む)が無視されてしまう。
Parameters
- $html : string
-
レンダリング済みの出力 HTML
- $config : array<string, mixed>
-
マージ済みの設定
Return values
string|null —書き換え後の HTML。テンプレートに meta が無ければ null
shouldInjectOptOutMeta()
オプトアウト宣言 <meta name="acms-htmx" content="disable"> をサーバー側で注入するか判定する。
public
shouldInjectOptOutMeta(string $html, string $strategy) : bool
off 戦略は静的読み込みをしないだけでなく、バンドルJSによる遅延読み込みも止める必要がある。 built-in/dispatch.js の遅延読み込みは「戦略が dynamic のとき」ではなく「window.htmx が 無いとき」に動くため、CMS が script タグを出さない off ではむしろ発動してしまう。 PHP から ACMS.Config へ値を渡す経路が無いので、テンプレート制作者が書くのと同じ オプトアウト宣言を注入して JS 側の判定に伝える。
Parameters
- $html : string
-
レンダリング済みの出力 HTML
- $strategy : string
-
config('htmx_load_strategy') の値(static | dynamic | off)
Return values
boolshouldLoadHtmxStatically()
DOM解析ではなく部分文字列で判定する。誤検出時のコストが「htmxを余分に読み込む」だけで 無害な一方、全リクエストで走る軽量な真偽判定にDOMDocumentは不釣り合いに重いため。
public
shouldLoadHtmxStatically(string $html, string $strategy) : bool
Parameters
- $html : string
-
レンダリング済みの出力 HTML
- $strategy : string
-
config('htmx_load_strategy') の値(static | dynamic | off)
Return values
booldispatchConfigHook()
private
dispatchConfigHook(array<string|int, mixed> &$config) : void
Parameters
- $config : array<string|int, mixed>
findTemplateConfigContent()
private
findTemplateConfigContent(string $html) : string|null
Parameters
- $html : string
-
レンダリング済みの出力 HTML
Return values
string|null —meta が無い・content 属性が無い場合は null
isOptedOut()
private
isOptedOut(string $html) : bool
Parameters
- $html : string
-
レンダリング済みの出力 HTML
Return values
boolmarks()
private
marks() : array<string|int, string>
Return values
array<string|int, string>replaceContentAttribute()
private
replaceContentAttribute(string $tag, string $encoded) : string
Parameters
- $tag : string
-
meta タグ 1 つ分の文字列
- $encoded : string
-
HTML エスケープ済みの JSON