Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Make XSD generation a low level command #130

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Classes/Fluid/ViewHelper/ComponentRendererFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace SMS\FluidComponents\Fluid\ViewHelper;

use Psr\Container\ContainerInterface;
use SMS\FluidComponents\Utility\ComponentArgumentConverter;
use SMS\FluidComponents\Utility\ComponentLoader;
use SMS\FluidComponents\Utility\ComponentSettings;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;

class ComponentRendererFactory
{
private ContainerInterface $container;

public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

public function create(): ComponentRenderer
{
return new ComponentRenderer(
$this->container->get(ComponentLoader::class),
new ComponentSettings(
new TypoScriptService()
),
new ComponentArgumentConverter(),
$this->container
);
}
}
16 changes: 8 additions & 8 deletions Classes/Fluid/ViewHelper/ComponentResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class ComponentResolver extends AbstractComponentResolver
*/
public function createViewHelperInstanceFromClassName($viewHelperClassName): ViewHelperInterface
{
if ($this->container instanceof FailsafeContainer) {
$classExists = class_exists($viewHelperClassName);
if ($this->container instanceof FailsafeContainer && $classExists) {
// The install tool creates VH instances using makeInstance to not rely on symfony DI here,
// otherwise we'd have to have all install-tool used ones in ServiceProvider.php. However,
// none of the install tool used VH's use injection.
Expand All @@ -33,19 +34,18 @@ public function createViewHelperInstanceFromClassName($viewHelperClassName): Vie
return $viewHelperInstance;
}

if (class_exists($viewHelperClassName, true)) {
if ($classExists) {
/** @var ViewHelperInterface $viewHelperInstance */
// @deprecated since v11, will be removed with 12. Fallback if extensions VH has no Services.yaml, yet.
$viewHelperInstance = $this->objectManager->get($viewHelperClassName);
return $viewHelperInstance;
} else {
// Redirect all components to special ViewHelper ComponentRenderer
$componentRenderer = $this->container->get(ComponentRenderer::class);
}

$componentRenderer->setComponentNamespace($viewHelperClassName);
// Redirect all components to special ViewHelper ComponentRenderer
$componentRenderer = $this->container->get(ComponentRendererFactory::class)->create();
$componentRenderer->setComponentNamespace($viewHelperClassName);

return $componentRenderer;
}
return $componentRenderer;
}

protected function getComponentLoader(): ComponentLoader
Expand Down
13 changes: 5 additions & 8 deletions Classes/Fluid/ViewHelper/LegacyComponentResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SMS\FluidComponents\Fluid\ViewHelper;

use SMS\FluidComponents\Fluid\ViewHelper\ComponentRenderer;
use SMS\FluidComponents\Utility\ComponentLoader;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface;
Expand All @@ -20,14 +19,12 @@ public function createViewHelperInstanceFromClassName($viewHelperClassName): Vie
{
if (class_exists($viewHelperClassName, true)) {
return $this->getObjectManager()->get($viewHelperClassName);
} else {
// Redirect all components to special ViewHelper ComponentRenderer
$componentRenderer = $this->getObjectManager()->get(ComponentRenderer::class);

$componentRenderer->setComponentNamespace($viewHelperClassName);

return $componentRenderer;
}
// Redirect all components to special ViewHelper ComponentRenderer
$componentRenderer = $this->getObjectManager()->get(ComponentRendererFactory::class)->create();
$componentRenderer->setComponentNamespace($viewHelperClassName);

return $componentRenderer;
}

protected function getComponentLoader(): ComponentLoader
Expand Down
3 changes: 2 additions & 1 deletion Classes/Service/XsdGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SMS\FluidComponents\Service;

use SMS\FluidComponents\Fluid\ViewHelper\ComponentRenderer;
use SMS\FluidComponents\Fluid\ViewHelper\ComponentRendererFactory;
use SMS\FluidComponents\Utility\ComponentLoader;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\ArgumentDefinition;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected function generateXsdForNamespace($namespace, $components)
$xsd = '<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="' . $this->getTargetXMLNameSpace($namespace) . '">' . "\n";
foreach ($components as $componentName => $componentFile) {
$componentRenderer = GeneralUtility::makeInstance(ComponentRenderer::class);
$componentRenderer = GeneralUtility::makeInstance(ComponentRendererFactory::class)->create();
$componentRenderer->setComponentNamespace($componentName);
$arguments = $componentRenderer->prepareArguments();
$componentNameWithoutNameSpace = $this->getTagName($namespace, $componentName);
Expand Down
80 changes: 75 additions & 5 deletions Classes/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
namespace SMS\FluidComponents;

use Psr\Container\ContainerInterface;
use SMS\FluidComponents\Command\GenerateXsdCommand;
use SMS\FluidComponents\Fluid\ViewHelper\ComponentRenderer;
use SMS\FluidComponents\Fluid\ViewHelper\ComponentRendererFactory;
use SMS\FluidComponents\Fluid\ViewHelper\ViewHelperResolverFactory;
use SMS\FluidComponents\Utility\ComponentArgumentConverter;
use SMS\FluidComponents\Utility\ComponentLoader;
use SMS\FluidComponents\Utility\ComponentSettings;
use TYPO3\CMS\Core\Console\CommandRegistry;
use TYPO3\CMS\Core\Package\AbstractServiceProvider;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolverFactoryInterface;

class ServiceProvider extends AbstractServiceProvider
{
Expand All @@ -18,15 +28,75 @@ protected static function getPackagePath(): string
public function getFactories(): array
{
return [
\TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolverFactoryInterface::class => [ static::class, 'getViewHelperResolverFactory' ],
ViewHelperResolverFactoryInterface::class => [ static::class, 'getViewHelperResolverFactory' ],
ComponentRendererFactory::class => [ static::class, 'getComponentRendererFactory' ],
ComponentLoader::class => [ static::class, 'getComponentLoader' ],
ComponentRenderer::class => [ static::class, 'getComponentRenderer' ],
GenerateXsdCommand::class => [ static::class, 'getGenerateXsdCommand' ],
];
}

public static function getViewHelperResolverFactory(ContainerInterface $container): Fluid\ViewHelper\ViewHelperResolverFactory
public function getExtensions(): array
{
return self::new($container, Fluid\ViewHelper\ViewHelperResolverFactory::class, [
return [
CommandRegistry::class => [ static::class, 'configureCommands' ],
] + parent::getExtensions();
}

public static function getViewHelperResolverFactory(ContainerInterface $container): ViewHelperResolverFactoryInterface
{
return self::new(
$container,
ViewHelperResolverFactory::class,
[
$container,
$container->get(ObjectManager::class)
]
);
}

public static function getComponentRendererFactory(ContainerInterface $container): ComponentRendererFactory
{
return self::new(
$container,
ComponentRendererFactory::class,
[
$container,
]
);
}

public static function getComponentLoader(ContainerInterface $container): ComponentLoader
{
return self::new(
$container,
$container->get(ObjectManager::class)
]);
ComponentLoader::class
);
}

public static function getComponentRenderer(ContainerInterface $container): ComponentRenderer
{
return $container->get(ComponentRendererFactory::class)->create();
}

public static function getGenerateXsdCommand(ContainerInterface $container): GenerateXsdCommand
{
return self::new(
$container,
GenerateXsdCommand::class,
[
'fluidcomponents:generatexsd',
]
);
}

public static function configureCommands(ContainerInterface $container, CommandRegistry $commandRegistry): CommandRegistry
{
$commandRegistry->addLazyCommand(
'fluidcomponents:generatexsd',
GenerateXsdCommand::class,
'Generates the XSD files for autocompletion in the IDE.'
);
return $commandRegistry;
}
}
12 changes: 3 additions & 9 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ services:

SMS\FluidComponents\:
resource: '../Classes/*'
exclude: '../Classes/Domain/Model/*'

SMS\FluidComponents\Command\GenerateXsdCommand:
tags:
- name: 'console.command'
command: 'fluidcomponents:generatexsd'
description: 'Generates the XSD files for autocompletion in the IDE.'
schedulable: true
hidden: false
exclude:
- '../Classes/Domain/Model/*'
- '../Classes/Interfaces/*'

SMS\FluidComponents\Command\CheckContentEscapingCommand:
tags:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"extra": {
"typo3/cms": {
"Package": {
"serviceProvider": "SMS\\FluidComponents\\ServiceProvider"
"serviceProvider": "SMS\\FluidComponents\\ServiceProvider",
"partOfMinimalUsableSystem": true
},
"cms-package-dir": "{$vendor-dir}/typo3/cms",
"app-dir": ".Build",
Expand Down