reelworx/t3-fakefrontend

一个为TYPO3扩展初始化“假前端”环境的库。主要用于CLI/BE目的。

v2.1.0 2024-06-26 14:35 UTC

This package is auto-updated.

Last update: 2024-08-26 12:58:49 UTC


README

这个库为TYPO3扩展提供了一个工具,用于引导一个假前端环境(TSFE和其他内容),可用于在其他上下文中进行前端相关操作,如后端或CLI。

何时使用此库?

如果您需要在非前端上下文中生成站点的绝对前端链接,这个库非常有用。

示例

  • 如果您在计划任务中生成邮件,邮件中应包含指向前端链接。一旦建立“假前端”,就可以使用常规的Fluid视图助手。
  • 如果您在后端模块中生成前端链接。

使用方法

// quickest usage
\Reelworx\TYPO3\FakeFrontend\FrontendUtility::executeInFEContext($pageUid, function () {
    // do some work
});
// *If you need to do some more stuff manually, here is the longer version:*

// Note: This populates the globals TSFE, TYPO3_REQUEST and $_SERVER['HTTP_HOST']
// It is advisable to reset/unset those again, when not needed anymore.
// Especially in BE context this can cause unexpected side effects.

// create a fully initialized TSFE for given page uid
$valid = \Reelworx\TYPO3\FakeFrontend\FrontendUtility::buildFakeFE($pageUid);
if ($valid) {
    //
    // ... do the work
    //
    \Reelworx\TYPO3\FakeFrontend\FrontendUtility::resetGlobals();
} else {
    // resetGlobals is done internally already
    throw new \RuntimeException('Building fake FE failed', 0, FrontendUtility::$lastError);
}

可以通过在页面模板中配置config.cliDomain来强制设置特定的$GLOBALS['TSFE']->absRefPrefix。值auto表示使用GeneralUtility::getIndpEnv('TYPO3_SITE_PATH')作为absRefPrefix。