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] Add float type support for component params #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions Classes/Domain/Model/FloatType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace SMS\FluidComponents\Domain\Model;

use SMS\FluidComponents\Interfaces\ConstructibleFromFloat;
use SMS\FluidComponents\Interfaces\ConstructibleFromInteger;
use SMS\FluidComponents\Interfaces\ConstructibleFromString;

class FloatType implements ConstructibleFromString, ConstructibleFromInteger, ConstructibleFromFloat
{
public static function fromString(string $value): float
{
return (float)$value;
}

public static function fromInteger(int $value): float
{
return (float)$value;
}

public static function fromFloat(float $value): float
{
return $value;
}
}
21 changes: 21 additions & 0 deletions Classes/Interfaces/ConstructibleFromFloat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace SMS\FluidComponents\Interfaces;

/**
* ConstructibleFromFloat defines an alternative constructor
* which "converts" the provided float to the class implementing
* the interface.
*
* The reason for this is because of php gettype() returning the string 'double' for float values for historical reasons
*/
interface ConstructibleFromFloat
{
/**
* Creates an instance of the class based on the provided integer
*
* @param float $value
* @return object
*/
public static function fromFloat(float $value);
}
5 changes: 5 additions & 0 deletions Classes/Utility/ComponentArgumentConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SMS\FluidComponents\Interfaces\ConstructibleFromDateTimeImmutable;
use SMS\FluidComponents\Interfaces\ConstructibleFromExtbaseFile;
use SMS\FluidComponents\Interfaces\ConstructibleFromFileInterface;
use SMS\FluidComponents\Interfaces\ConstructibleFromFloat;
use SMS\FluidComponents\Interfaces\ConstructibleFromInteger;
use SMS\FluidComponents\Interfaces\ConstructibleFromNull;
use SMS\FluidComponents\Interfaces\ConstructibleFromString;
Expand All @@ -32,6 +33,10 @@ class ComponentArgumentConverter implements \TYPO3\CMS\Core\SingletonInterface
ConstructibleFromInteger::class,
'fromInteger'
],
'double' => [
ConstructibleFromFloat::class,
'fromFloat'
],
'array' => [
ConstructibleFromArray::class,
'fromArray'
Expand Down
1 change: 1 addition & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['fluid_components']['typeAliases']['NavigationItem'] = \SMS\FluidComponents\Domain\Model\NavigationItem::class;
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['fluid_components']['typeAliases']['Labels'] = \SMS\FluidComponents\Domain\Model\Labels::class;
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['fluid_components']['typeAliases']['Slot'] = \SMS\FluidComponents\Domain\Model\Slot::class;
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['fluid_components']['typeAliases']['float'] = \SMS\FluidComponents\Domain\Model\FloatType::class;

if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['fluidComponents.partialsInComponents'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['fluidComponents.partialsInComponents'] = false;
Expand Down