TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Fluid\View;
|
||||
|
||||
use TYPO3\CMS\Core\View\ViewInterface as CoreViewInterface;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\View\AbstractTemplateView as FluidStandaloneAbstractTemplateView;
|
||||
use TYPO3Fluid\Fluid\View\TemplateAwareViewInterface as FluidStandaloneTemplateAwareViewInterface;
|
||||
use TYPO3Fluid\Fluid\View\ViewInterface as FluidStandaloneViewInterface;
|
||||
|
||||
/**
|
||||
* A view adapter that handles a Typo3Fluid view and implements generic ext:core ViewInterface.
|
||||
*
|
||||
* @internal This is a specific view adapter is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
readonly class FluidViewAdapter implements CoreViewInterface, FluidStandaloneViewInterface, FluidStandaloneTemplateAwareViewInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected FluidStandaloneViewInterface&FluidStandaloneTemplateAwareViewInterface $view,
|
||||
) {}
|
||||
|
||||
public function assign(string $key, mixed $value): self
|
||||
{
|
||||
$this->view->assign($key, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function assignMultiple(array $values): self
|
||||
{
|
||||
$this->view->assignMultiple($values);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render(string $templateFileName = ''): string
|
||||
{
|
||||
$renderedView = $this->view->render($templateFileName);
|
||||
if ($renderedView !== null && !is_scalar($renderedView) && !$renderedView instanceof \Stringable) {
|
||||
throw new \RuntimeException('The rendered Fluid view can not be turned into string', 1731959329);
|
||||
}
|
||||
return (string)$renderedView;
|
||||
}
|
||||
|
||||
public function getRenderingContext(): RenderingContextInterface
|
||||
{
|
||||
if ($this->view instanceof FluidStandaloneAbstractTemplateView) {
|
||||
return $this->view->getRenderingContext();
|
||||
}
|
||||
throw new \RuntimeException('view must be an instance of ext:fluid \TYPO3Fluid\Fluid\View\AbstractTemplateView', 1721889095);
|
||||
}
|
||||
|
||||
public function setRenderingContext(RenderingContextInterface $renderingContext): void
|
||||
{
|
||||
if ($this->view instanceof FluidStandaloneAbstractTemplateView) {
|
||||
$this->view->setRenderingContext($renderingContext);
|
||||
return;
|
||||
}
|
||||
throw new \RuntimeException('view must be an instance of ext:fluid \TYPO3Fluid\Fluid\View\AbstractTemplateView', 1721578954);
|
||||
}
|
||||
|
||||
public function renderSection($sectionName, array $variables = [], $ignoreUnknown = false): mixed
|
||||
{
|
||||
if ($this->view instanceof FluidStandaloneAbstractTemplateView) {
|
||||
return $this->view->renderSection($sectionName, $variables, $ignoreUnknown);
|
||||
}
|
||||
throw new \RuntimeException('view must be an instance of ext:fluid \TYPO3Fluid\Fluid\View\AbstractTemplateView', 1721746411);
|
||||
}
|
||||
|
||||
public function renderPartial($partialName, $sectionName, array $variables, $ignoreUnknown = false): mixed
|
||||
{
|
||||
if ($this->view instanceof FluidStandaloneAbstractTemplateView) {
|
||||
return $this->view->renderPartial($partialName, $sectionName, $variables, $ignoreUnknown);
|
||||
}
|
||||
throw new \RuntimeException('view must be an instance of ext:fluid \TYPO3Fluid\Fluid\View\AbstractTemplateView', 1721746412);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Fluid\View;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
|
||||
use TYPO3\CMS\Core\View\ViewFactoryData;
|
||||
use TYPO3\CMS\Core\View\ViewFactoryInterface;
|
||||
use TYPO3\CMS\Core\View\ViewInterface;
|
||||
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
|
||||
use TYPO3Fluid\Fluid\View\TemplateView;
|
||||
|
||||
/**
|
||||
* Create a view based on fluid.
|
||||
*
|
||||
* Return an instance of ext:fluid FluidViewAdapter that implements ext:core ViewInterface.
|
||||
*
|
||||
* This is the default implementation when a class asks for a ViewFactoryInterface injection.
|
||||
*
|
||||
* @internal This is a specific view factory is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
#[AsAlias(ViewFactoryInterface::class, public: true)]
|
||||
final readonly class FluidViewFactory implements ViewFactoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
private RenderingContextFactory $renderingContextFactory,
|
||||
) {}
|
||||
|
||||
public function create(ViewFactoryData $data): ViewInterface
|
||||
{
|
||||
$pathTuple = [];
|
||||
if (!empty($data->templateRootPaths)) {
|
||||
$pathTuple['templateRootPaths'] = $data->templateRootPaths;
|
||||
}
|
||||
if (!empty($data->layoutRootPaths)) {
|
||||
$pathTuple['layoutRootPaths'] = $data->layoutRootPaths;
|
||||
}
|
||||
if (!empty($data->partialRootPaths)) {
|
||||
$pathTuple['partialRootPaths'] = $data->partialRootPaths;
|
||||
}
|
||||
$renderingContext = $this->renderingContextFactory->create($pathTuple, $data->request);
|
||||
if ($data->templatePathAndFilename) {
|
||||
$renderingContext->getTemplatePaths()->setTemplatePathAndFilename($data->templatePathAndFilename);
|
||||
}
|
||||
if ($data->format) {
|
||||
// @todo: We may want to hand this over to RenderingContextFactory
|
||||
// and set up TemplatePaths() with the format correctly already?
|
||||
$renderingContext->getTemplatePaths()->setFormat($data->format);
|
||||
}
|
||||
$view = new TemplateView($renderingContext);
|
||||
return new FluidViewAdapter($view);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Fluid\View;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\ArrayUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Utility\PathUtility;
|
||||
|
||||
/**
|
||||
* Custom implementation for template paths resolving, one which differs from the base
|
||||
* implementation in that it is capable of resolving template paths based on TypoScript
|
||||
* configuration when given a package name, and is aware of the Frontend/Backend contexts of TYPO3.
|
||||
*
|
||||
* @internal This is for internal Fluid use only.
|
||||
*/
|
||||
class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
|
||||
{
|
||||
/**
|
||||
* Overridden setter with enforced sorting behavior
|
||||
*/
|
||||
public function setTemplateRootPaths(array $templateRootPaths): void
|
||||
{
|
||||
parent::setTemplateRootPaths(ArrayUtility::sortArrayWithIntegerKeys($templateRootPaths));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden setter with enforced sorting behavior
|
||||
*/
|
||||
public function setLayoutRootPaths(array $layoutRootPaths): void
|
||||
{
|
||||
parent::setLayoutRootPaths(ArrayUtility::sortArrayWithIntegerKeys($layoutRootPaths));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden setter with enforced sorting behavior
|
||||
*/
|
||||
public function setPartialRootPaths(array $partialRootPaths): void
|
||||
{
|
||||
parent::setPartialRootPaths(ArrayUtility::sortArrayWithIntegerKeys($partialRootPaths));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get absolute path to template file
|
||||
*
|
||||
* @return string|null Returns the absolute path to a Fluid template file
|
||||
*/
|
||||
public function getTemplatePathAndFilename(): ?string
|
||||
{
|
||||
return $this->templatePathAndFilename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Guarantees that $reference is turned into a
|
||||
* correct, absolute path. The input can be a
|
||||
* relative path or a FILE: or EXT: reference
|
||||
* but cannot be a FAL resource identifier.
|
||||
*
|
||||
* @param string $reference
|
||||
*/
|
||||
protected function ensureAbsolutePath($reference): string
|
||||
{
|
||||
return PathUtility::isAbsolutePath($reference) ? $reference : GeneralUtility::getFileAbsFileName($reference);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user