Skip to content

Commit

Permalink
[TASK] Convert Providers and directly associated classes to construct…
Browse files Browse the repository at this point in the history
…or injection
  • Loading branch information
NamelessCoder committed Jul 29, 2023
1 parent d8e59b5 commit 84b6551
Show file tree
Hide file tree
Showing 28 changed files with 609 additions and 439 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
declare(strict_types=1);
namespace FluidTYPO3\Flux\Utility;
namespace FluidTYPO3\Flux\Builder;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
Expand All @@ -10,6 +10,7 @@
*/

use FluidTYPO3\Flux\Integration\Configuration\ConfigurationContext;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
declare(strict_types=1);
namespace FluidTYPO3\Flux\Utility;
namespace FluidTYPO3\Flux\Builder;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
Expand All @@ -9,6 +9,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\TypoScript\AST\Node\RootNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
declare(strict_types=1);
namespace FluidTYPO3\Flux\Integration;
namespace FluidTYPO3\Flux\Builder;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
Expand All @@ -9,14 +9,21 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Utility\RenderingContextBuilder;
use FluidTYPO3\Flux\Integration\PreviewView;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\TemplateView;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\View\ViewInterface;

class ViewBuilder
{
protected RenderingContextBuilder $renderingContextBuilder;

public function __construct(RenderingContextBuilder $renderingContextBuilder)
{
$this->renderingContextBuilder = $renderingContextBuilder;
}

public function buildPreviewView(
string $extensionIdentity,
string $controllerName,
Expand Down Expand Up @@ -67,9 +74,7 @@ private function buildRenderingContext(
string $controllerAction,
?string $templatePathAndFilename
): RenderingContextInterface {
/** @var RenderingContextBuilder $renderingContextBuilder */
$renderingContextBuilder = GeneralUtility::makeInstance(RenderingContextBuilder::class);
return $renderingContextBuilder->buildRenderingContextFor(
return $this->renderingContextBuilder->buildRenderingContextFor(
$extensionIdentity,
$controllerName,
$controllerAction,
Expand Down
2 changes: 1 addition & 1 deletion Classes/Content/ContentTypeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Builder\ViewBuilder;
use FluidTYPO3\Flux\Content\TypeDefinition\ContentTypeDefinitionInterface;
use FluidTYPO3\Flux\Content\TypeDefinition\FluidRenderingContentTypeDefinitionInterface;
use FluidTYPO3\Flux\Integration\ViewBuilder;
use FluidTYPO3\Flux\Service\TemplateValidationService;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
Expand Down
19 changes: 11 additions & 8 deletions Classes/Content/RuntimeDefinedContentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Builder\ViewBuilder;
use FluidTYPO3\Flux\Content\TypeDefinition\FluidRenderingContentTypeDefinitionInterface;
use FluidTYPO3\Flux\Content\TypeDefinition\RecordBased\RecordBasedContentTypeDefinition;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Form\Container\Grid;
use FluidTYPO3\Flux\Provider\AbstractProvider;
use FluidTYPO3\Flux\Provider\Interfaces\GridProviderInterface;
use FluidTYPO3\Flux\Service\FluxService;
use FluidTYPO3\Flux\Service\WorkspacesAwareRecordService;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Flux Provider for runtime-defined content types
Expand All @@ -37,13 +39,14 @@ class RuntimeDefinedContentProvider extends AbstractProvider implements GridProv

protected ContentTypeManager $contentTypeDefinitions;

public function __construct()
{
parent::__construct();

/** @var ContentTypeManager $contentTypes */
$contentTypes = GeneralUtility::makeInstance(ContentTypeManager::class);
$this->contentTypeDefinitions = $contentTypes;
public function __construct(
FluxService $configurationService,
WorkspacesAwareRecordService $recordService,
ViewBuilder $viewBuilder,
ContentTypeManager $contentTypeManager
) {
parent::__construct($configurationService, $recordService, $viewBuilder);
$this->contentTypeDefinitions = $contentTypeManager;
}

public function trigger(array $row, ?string $table, ?string $field, ?string $extensionKey = null): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Builder\ViewBuilder;
use FluidTYPO3\Flux\Content\ContentGridForm;
use FluidTYPO3\Flux\Content\ContentTypeManager;
use FluidTYPO3\Flux\Content\TypeDefinition\ContentTypeDefinitionInterface;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Form\Container\Grid;
use FluidTYPO3\Flux\Provider\AbstractProvider;
use FluidTYPO3\Flux\Provider\Interfaces\GridProviderInterface;
use FluidTYPO3\Flux\Service\FluxService;
use FluidTYPO3\Flux\Service\WorkspacesAwareRecordService;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand All @@ -34,12 +37,13 @@ class RecordBasedContentGridProvider extends AbstractProvider implements GridPro

protected ContentTypeManager $contentTypeDefinitions;

public function __construct()
{
parent::__construct();

/** @var ContentTypeManager $contentTypeManager */
$contentTypeManager = GeneralUtility::makeInstance(ContentTypeManager::class);
public function __construct(
FluxService $configurationService,
WorkspacesAwareRecordService $recordService,
ViewBuilder $viewBuilder,
ContentTypeManager $contentTypeManager
) {
parent::__construct($configurationService, $recordService, $viewBuilder);
$this->contentTypeDefinitions = $contentTypeManager;
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/AbstractFluxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Builder\RenderingContextBuilder;
use FluidTYPO3\Flux\Builder\RequestBuilder;
use FluidTYPO3\Flux\Hooks\HookHandler;
use FluidTYPO3\Flux\Integration\NormalizedData\DataAccessTrait;
use FluidTYPO3\Flux\Provider\Interfaces\ControllerProviderInterface;
Expand All @@ -17,8 +19,6 @@
use FluidTYPO3\Flux\Service\FluxService;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
use FluidTYPO3\Flux\Utility\RecursiveArrayUtility;
use FluidTYPO3\Flux\Utility\RenderingContextBuilder;
use FluidTYPO3\Flux\Utility\RequestBuilder;
use FluidTYPO3\Flux\ViewHelpers\FormViewHelper;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Builder\RequestBuilder;
use FluidTYPO3\Flux\Content\ContentTypeManager;
use FluidTYPO3\Flux\Core;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Integration\ContentTypeBuilder;
use FluidTYPO3\Flux\Provider\Provider;
use FluidTYPO3\Flux\Provider\ProviderInterface;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
use FluidTYPO3\Flux\Utility\RequestBuilder;
use TYPO3\CMS\Core\Core\ApplicationContext;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down
17 changes: 6 additions & 11 deletions Classes/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Builder\ViewBuilder;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Form\Container\Grid;
use FluidTYPO3\Flux\Hooks\HookHandler;
use FluidTYPO3\Flux\Integration\ViewBuilder;
use FluidTYPO3\Flux\Service\FluxService;
use FluidTYPO3\Flux\Service\WorkspacesAwareRecordService;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
Expand Down Expand Up @@ -73,18 +73,13 @@ class AbstractProvider implements ProviderInterface
protected WorkspacesAwareRecordService $recordService;
protected ViewBuilder $viewBuilder;

public function __construct()
{
/** @var FluxService $configurationService */
$configurationService = GeneralUtility::makeInstance(FluxService::class);
public function __construct(
FluxService $configurationService,
WorkspacesAwareRecordService $recordService,
ViewBuilder $viewBuilder
) {
$this->configurationService = $configurationService;

/** @var WorkspacesAwareRecordService $recordService */
$recordService = GeneralUtility::makeInstance(WorkspacesAwareRecordService::class);
$this->recordService = $recordService;

/** @var ViewBuilder $viewBuilder */
$viewBuilder = GeneralUtility::makeInstance(ViewBuilder::class);
$this->viewBuilder = $viewBuilder;
}

Expand Down
16 changes: 10 additions & 6 deletions Classes/Provider/PageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Builder\ViewBuilder;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Integration\PreviewView;
use FluidTYPO3\Flux\Service\FluxService;
use FluidTYPO3\Flux\Service\PageService;
use FluidTYPO3\Flux\Service\WorkspacesAwareRecordService;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
use FluidTYPO3\Flux\Utility\RecursiveArrayUtility;
use TYPO3\CMS\Core\DataHandling\DataHandler;
Expand Down Expand Up @@ -45,12 +48,13 @@ class PageProvider extends AbstractProvider implements ProviderInterface

protected PageService $pageService;

public function __construct()
{
parent::__construct();

/** @var PageService $pageService */
$pageService = GeneralUtility::makeInstance(PageService::class);
public function __construct(
FluxService $configurationService,
WorkspacesAwareRecordService $recordService,
ViewBuilder $viewBuilder,
PageService $pageService
) {
parent::__construct($configurationService, $recordService, $viewBuilder);
$this->pageService = $pageService;
}

Expand Down
2 changes: 0 additions & 2 deletions Classes/Service/FluxService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
use TYPO3\CMS\Fluid\View\TemplatePaths;
Expand Down
1 change: 0 additions & 1 deletion Classes/Service/PageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Fluid\View\TemplatePaths;
use TYPO3\CMS\Fluid\View\TemplateView;
Expand Down
25 changes: 24 additions & 1 deletion Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,30 @@ services:
public: true
FluidTYPO3\Flux\Integration\Configuration\SpooledConfigurationApplicator:
public: true
FluidTYPO3\Flux\Utility\RenderingContextBuilder:
FluidTYPO3\Flux\Builder\RenderingContextBuilder:
public: true
FluidTYPO3\Flux\Builder\ViewBuilder:
public: true
FluidTYPO3\Flux\Provider\Provider:
shared: false
public: true
FluidTYPO3\Flux\Provider\ContentProvider:
shared: false
public: true
FluidTYPO3\Flux\Provider\PageProvider:
shared: false
public: true
FluidTYPO3\Flux\Provider\SubPageProvider:
shared: false
public: true
FluidTYPO3\Flux\Content\RuntimeDefinedContentProvider:
shared: false
public: true
FluidTYPO3\Flux\Content\ContentTypeProvider:
shared: false
public: true
FluidTYPO3\Flux\Content\TypeDefinition\RecordBased\RecordBasedContentGridProvider:
shared: false
public: true
FluidTYPO3\Flux\Form\Transformation\FormDataTransformer:
public: true
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,14 @@ Flux feature highlights
* Several Utility-type classes for advanced integrations with Fluid in particular.


Known issues
------------
Caveats
-------

* Keep In mind to have your PHP/HTTP configured correctly to accept a fairly large number of input fields. When nesting
sections / objects the number of fields submitted, rises drastically. The `php.ini` configuration setting to think about is
`max_input_vars`. If this number is too small then the TYPO3 Backend (being PHP) will decline the submission of the
backend editing form and will exit with an "Invalid CSRF Token" message because of incomplete (truncated) `POST` data.
* When working with custom Provider classes: 1) make sure you declare each Provider class as `public: true` in Service
config of your extension. And 2) if the Provider needs to be used for more than one specific page/content/record type,
make sure you also declare the Provider as `shared: false`. You can find an example of such configuration in the
`Configuration/Services.yaml` file in Flux.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace FluidTYPO3\Flux\Tests\Unit\Integration;
namespace FluidTYPO3\Flux\Tests\Unit\Builder;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
Expand All @@ -8,10 +8,10 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Builder\RenderingContextBuilder;
use FluidTYPO3\Flux\Builder\RequestBuilder;
use FluidTYPO3\Flux\Integration\Configuration\ConfigurationContext;
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase;
use FluidTYPO3\Flux\Utility\RenderingContextBuilder;
use FluidTYPO3\Flux\Utility\RequestBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
Expand Down
Loading

0 comments on commit 84b6551

Please sign in to comment.