From 978932049ea50a26333eff7fda7921fe068da155 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Mon, 8 Jun 2020 11:05:31 +0200 Subject: [PATCH 1/4] [FEATURE] Component aware data structures --- Classes/Fluid/ViewHelper/ComponentRenderer.php | 7 +++++++ Classes/Interfaces/ComponentAware.php | 15 +++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 Classes/Interfaces/ComponentAware.php diff --git a/Classes/Fluid/ViewHelper/ComponentRenderer.php b/Classes/Fluid/ViewHelper/ComponentRenderer.php index 1c2f1d5..335c55d 100644 --- a/Classes/Fluid/ViewHelper/ComponentRenderer.php +++ b/Classes/Fluid/ViewHelper/ComponentRenderer.php @@ -2,6 +2,7 @@ namespace SMS\FluidComponents\Fluid\ViewHelper; +use SMS\FluidComponents\Interfaces\ComponentAware; use SMS\FluidComponents\Utility\ComponentArgumentConverter; use SMS\FluidComponents\Utility\ComponentLoader; use SMS\FluidComponents\Utility\ComponentPrefixer\ComponentPrefixerInterface; @@ -148,6 +149,12 @@ public function render() $argumentType = $this->argumentDefinitions[$name]->getType(); $argument = $componentArgumentConverter->convertValueToType($argument, $argumentType); + + // Provide component namespace to certain data structures + if ($argument instanceof ComponentAware) { + $argument->setComponentNamespace($this->componentNamespace); + } + $variableContainer->add($name, $argument); } diff --git a/Classes/Interfaces/ComponentAware.php b/Classes/Interfaces/ComponentAware.php new file mode 100644 index 0000000..e1c5ede --- /dev/null +++ b/Classes/Interfaces/ComponentAware.php @@ -0,0 +1,15 @@ + Date: Mon, 8 Jun 2020 11:27:37 +0200 Subject: [PATCH 2/4] [TASK] Add interface to initialize data structures from null --- Classes/Interfaces/ConstructibleFromNull.php | 17 +++++++++++++++++ Classes/Utility/ComponentArgumentConverter.php | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 Classes/Interfaces/ConstructibleFromNull.php diff --git a/Classes/Interfaces/ConstructibleFromNull.php b/Classes/Interfaces/ConstructibleFromNull.php new file mode 100644 index 0000000..93b5ca5 --- /dev/null +++ b/Classes/Interfaces/ConstructibleFromNull.php @@ -0,0 +1,17 @@ + [ + ConstructibleFromNull::class, + 'fromNull' + ], FileReference::class => [ ConstructibleFromFileInterface::class, 'fromFileInterface' From bc23ed5b1855591d7050b352e3141f3db3c6e641 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Mon, 8 Jun 2020 11:28:02 +0200 Subject: [PATCH 3/4] [FEATURE] Implement cache for argument converter to improve performance --- .../Utility/ComponentArgumentConverter.php | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/Classes/Utility/ComponentArgumentConverter.php b/Classes/Utility/ComponentArgumentConverter.php index db1755d..38f930e 100644 --- a/Classes/Utility/ComponentArgumentConverter.php +++ b/Classes/Utility/ComponentArgumentConverter.php @@ -60,6 +60,13 @@ class ComponentArgumentConverter implements \TYPO3\CMS\Core\SingletonInterface ], ]; + /** + * Runtime cache to speed up conversion checks + * + * @var array + */ + protected $conversionCache = []; + /** * Adds an interface to specify argument type conversion to list * @@ -96,22 +103,32 @@ public function removeConversionInterface(string $fromType): self */ public function canTypeBeConvertedToType(string $givenType, string $toType): bool { - // Check if a constructor interface exists for the given type - if (!isset($this->conversionInterfaces[$givenType])) { + // No need to convert equal types + if ($givenType === $toType) { return false; } + // Has this check already been computed? + if (isset($this->conversionCache[$givenType . '|' . $toType])) { + return $this->conversionCache[$givenType . '|' . $toType]; + } + + // Check if a constructor interface exists for the given type // Check if the target type is a PHP class - if (!class_exists($toType)) { - return false; + $canBeConverted = false; + if (isset($this->conversionInterfaces[$givenType]) && class_exists($toType)) { + // Check if the target type implements the constructor interface + // required for conversion + $canBeConverted = is_subclass_of( + $toType, + $this->conversionInterfaces[$givenType][0] + ); } - // Check if the target type implements the constructor interface - // required for conversion - return is_subclass_of( - $toType, - $this->conversionInterfaces[$givenType][0] - ); + // Add to runtime cache + $this->conversionCache[$givenType . '|' . $toType] = $canBeConverted; + + return $canBeConverted; } /** From 849be1f76184043aedd9839c18583646cf443254 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Mon, 8 Jun 2020 12:09:03 +0200 Subject: [PATCH 4/4] [TASK] Increment version number to 2.1.0 --- ext_emconf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_emconf.php b/ext_emconf.php index 660e08b..dbc2b3a 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -9,7 +9,7 @@ 'state' => 'stable', 'uploadfolder' => false, 'clearCacheOnLoad' => false, - 'version' => '2.0.1', + 'version' => '2.1.0', 'constraints' => [ 'depends' => [ 'typo3' => '9.5.0-10.9.99',