helhum/typo3-frontend-request

API,用于从代码或命令行执行TYPO3前端请求

v1.2.0 2024-06-17 18:27 UTC

This package is auto-updated.

Last update: 2024-09-17 19:14:43 UTC


README

此包提供了一个API,可以在任何上下文中获取任何TYPO3前端请求的响应,无需实际进行HTTP请求。

示例

执行TYPO3前端请求

$request = new \TYPO3\CMS\Core\Http\ServerRequest($uri);
$client = new \Helhum\Typo3FrontendRequest\Typo3Client();
try {
    $response = $client->send($request);
    $body = (string)$response->getBody();
} catch (\Helhum\Typo3FrontendRequest\RequestFailed $e) {
    throw new \RuntimeException('Could not fetch  page "' . $uri . '", reason: ' . $e->getMessage(), 1552081550, $e);
}

执行已认证用户的TYPO3前端请求

$request = new \TYPO3\CMS\Core\Http\ServerRequest($uri)
$request = $request->withHeader(
    'x-typo3-frontend-user',
    (string)$context->getPropertyFromAspect('frontend.user', 'id')
);
$client = new \Helhum\Typo3FrontendRequest\Typo3Client();
$response = $client->send($request);
$body = (string)$response->getBody();