TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
<?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\Core\Imaging\ImageManipulation;
|
||||
|
||||
use TYPO3\CMS\Core\Resource\FileInterface;
|
||||
|
||||
class Area
|
||||
{
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $x;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $y;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
public function __construct(float $x, float $y, float $width, float $height)
|
||||
{
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigurationException
|
||||
*/
|
||||
public static function createFromConfiguration(array $config): Area
|
||||
{
|
||||
try {
|
||||
return new self(
|
||||
(float)$config['x'],
|
||||
(float)$config['y'],
|
||||
(float)$config['width'],
|
||||
(float)$config['height']
|
||||
);
|
||||
} catch (\Throwable $throwable) {
|
||||
throw new InvalidConfigurationException(sprintf('Invalid type for area property given: %s', $throwable->getMessage()), 1485279226, $throwable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Area[]
|
||||
* @throws InvalidConfigurationException
|
||||
*/
|
||||
public static function createMultipleFromConfiguration(array $config): array
|
||||
{
|
||||
$areas = [];
|
||||
foreach ($config as $areaConfig) {
|
||||
$areas[] = self::createFromConfiguration($areaConfig);
|
||||
}
|
||||
return $areas;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Area
|
||||
*/
|
||||
public static function createEmpty()
|
||||
{
|
||||
return new self(0.0, 0.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
public function getWidth(): float
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function getHeight(): float
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
public function getOffsetLeft(): float
|
||||
{
|
||||
return $this->x;
|
||||
}
|
||||
|
||||
public function getOffsetTop(): float
|
||||
{
|
||||
return $this->y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function asArray(): array
|
||||
{
|
||||
return [
|
||||
'x' => $this->x,
|
||||
'y' => $this->y,
|
||||
'width' => $this->width,
|
||||
'height' => $this->height,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Area
|
||||
*/
|
||||
public function makeAbsoluteBasedOnFile(FileInterface $file)
|
||||
{
|
||||
return new self(
|
||||
$this->x * $file->getProperty('width'),
|
||||
$this->y * $file->getProperty('height'),
|
||||
$this->width * $file->getProperty('width'),
|
||||
$this->height * $file->getProperty('height')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Area
|
||||
*/
|
||||
public function makeRelativeBasedOnFile(FileInterface $file)
|
||||
{
|
||||
$width = $file->getProperty('width');
|
||||
$height = $file->getProperty('height');
|
||||
|
||||
if (empty($width) || empty($height)) {
|
||||
return self::createEmpty();
|
||||
}
|
||||
|
||||
return new self(
|
||||
$this->x / $width,
|
||||
$this->y / $height,
|
||||
$this->width / $width,
|
||||
$this->height / $height
|
||||
);
|
||||
}
|
||||
|
||||
public function applyRatioRestriction(Ratio $ratio): Area
|
||||
{
|
||||
if ($ratio->isFree()) {
|
||||
return $this;
|
||||
}
|
||||
$expectedRatio = $ratio->getRatioValue();
|
||||
$newArea = clone $this;
|
||||
if ($newArea->height * $expectedRatio > $newArea->width) {
|
||||
$newArea->height = $newArea->width / $expectedRatio;
|
||||
$newArea->y += ($this->height - $newArea->height) / 2;
|
||||
} else {
|
||||
$newArea->width = $newArea->height * $expectedRatio;
|
||||
$newArea->x += ($this->width - $newArea->width) / 2;
|
||||
}
|
||||
return $newArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->x === 0.0 && $this->y === 0.0 && $this->width === 1.0 && $this->height === 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
return json_encode($this->asArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
<?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\Core\Imaging\ImageManipulation;
|
||||
|
||||
use TYPO3\CMS\Core\Resource\FileInterface;
|
||||
|
||||
class CropVariant
|
||||
{
|
||||
/**
|
||||
* @var Ratio[]
|
||||
*/
|
||||
protected array $allowedAspectRatios = [];
|
||||
|
||||
protected string $selectedRatio = '';
|
||||
protected ?Area $focusArea = null;
|
||||
|
||||
/**
|
||||
* @var Area[]|null
|
||||
*/
|
||||
protected ?array $coverAreas = null;
|
||||
|
||||
protected bool $excludeFromSync = false;
|
||||
|
||||
/**
|
||||
* @param Ratio[] $allowedAspectRatios
|
||||
* @param string|null $selectedRatio
|
||||
* @param Area|null $focusArea
|
||||
* @param Area[]|null $coverAreas
|
||||
* @throws InvalidConfigurationException
|
||||
*/
|
||||
public function __construct(
|
||||
protected string $id,
|
||||
protected string $title,
|
||||
protected Area $cropArea,
|
||||
?array $allowedAspectRatios = null,
|
||||
?string $selectedRatio = null,
|
||||
?Area $focusArea = null,
|
||||
?array $coverAreas = null,
|
||||
bool $excludeFromSync = false
|
||||
) {
|
||||
if ($allowedAspectRatios) {
|
||||
$this->setAllowedAspectRatios(...$allowedAspectRatios);
|
||||
if ($selectedRatio && isset($this->allowedAspectRatios[$selectedRatio])) {
|
||||
$this->selectedRatio = $selectedRatio;
|
||||
} else {
|
||||
$this->selectedRatio = current($this->allowedAspectRatios)->getId();
|
||||
}
|
||||
}
|
||||
$this->focusArea = $focusArea;
|
||||
if ($coverAreas !== null) {
|
||||
$this->setCoverAreas(...$coverAreas);
|
||||
}
|
||||
$this->excludeFromSync = $excludeFromSync;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigurationException
|
||||
*/
|
||||
public static function createFromConfiguration(string $id, array $config): CropVariant
|
||||
{
|
||||
try {
|
||||
return new self(
|
||||
$id,
|
||||
$config['title'] ?? '',
|
||||
Area::createFromConfiguration($config['cropArea']),
|
||||
isset($config['allowedAspectRatios']) ? Ratio::createMultipleFromConfiguration($config['allowedAspectRatios']) : null,
|
||||
$config['selectedRatio'] ?? null,
|
||||
isset($config['focusArea']) ? Area::createFromConfiguration($config['focusArea']) : null,
|
||||
isset($config['coverAreas']) ? Area::createMultipleFromConfiguration($config['coverAreas']) : null,
|
||||
isset($config['excludeFromSync']) ? filter_var($config['excludeFromSync'], FILTER_VALIDATE_BOOLEAN) : false,
|
||||
);
|
||||
} catch (\Throwable $throwable) {
|
||||
throw new InvalidConfigurationException(sprintf('Invalid type in configuration for crop variant: %s', $throwable->getMessage()), 1485278693, $throwable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function asArray(): array
|
||||
{
|
||||
$coverAreasAsArray = null;
|
||||
$allowedAspectRatiosAsArray = [];
|
||||
foreach ($this->allowedAspectRatios as $id => $allowedAspectRatio) {
|
||||
$allowedAspectRatiosAsArray[$id] = $allowedAspectRatio->asArray();
|
||||
}
|
||||
if ($this->coverAreas !== null) {
|
||||
$coverAreasAsArray = [];
|
||||
foreach ($this->coverAreas as $coverArea) {
|
||||
$coverAreasAsArray[] = $coverArea->asArray();
|
||||
}
|
||||
}
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'cropArea' => $this->cropArea->asArray(),
|
||||
'allowedAspectRatios' => $allowedAspectRatiosAsArray,
|
||||
'selectedRatio' => $this->selectedRatio,
|
||||
'focusArea' => $this->focusArea?->asArray(),
|
||||
'coverAreas' => $coverAreasAsArray ?? null,
|
||||
'excludeFromSync' => $this->excludeFromSync,
|
||||
];
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getCropArea(): Area
|
||||
{
|
||||
return $this->cropArea;
|
||||
}
|
||||
|
||||
public function getFocusArea(): ?Area
|
||||
{
|
||||
return $this->focusArea;
|
||||
}
|
||||
|
||||
public function applyRatioRestrictionToSelectedCropArea(FileInterface $file): CropVariant
|
||||
{
|
||||
if (!$this->selectedRatio) {
|
||||
return $this;
|
||||
}
|
||||
$newVariant = clone $this;
|
||||
$newArea = $this->cropArea->makeAbsoluteBasedOnFile($file);
|
||||
$newArea = $newArea->applyRatioRestriction($this->allowedAspectRatios[$this->selectedRatio]);
|
||||
$newVariant->cropArea = $newArea->makeRelativeBasedOnFile($file);
|
||||
return $newVariant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigurationException
|
||||
*/
|
||||
protected function setAllowedAspectRatios(Ratio ...$ratios): void
|
||||
{
|
||||
$this->allowedAspectRatios = [];
|
||||
foreach ($ratios as $ratio) {
|
||||
$this->addAllowedAspectRatio($ratio);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigurationException
|
||||
*/
|
||||
protected function addAllowedAspectRatio(Ratio $ratio): void
|
||||
{
|
||||
if (isset($this->allowedAspectRatios[$ratio->getId()])) {
|
||||
throw new InvalidConfigurationException(sprintf('Ratio with with duplicate ID (%s) is configured. Make sure all configured ratios have different ids.', $ratio->getId()), 1485274618);
|
||||
}
|
||||
$this->allowedAspectRatios[$ratio->getId()] = $ratio;
|
||||
}
|
||||
|
||||
protected function setCoverAreas(Area ...$areas): void
|
||||
{
|
||||
$this->coverAreas = [];
|
||||
foreach ($areas as $area) {
|
||||
$this->addCoverArea($area);
|
||||
}
|
||||
}
|
||||
|
||||
protected function addCoverArea(Area $area): void
|
||||
{
|
||||
$this->coverAreas[] = $area;
|
||||
}
|
||||
|
||||
public function isExcludeFromSync(): bool
|
||||
{
|
||||
return $this->excludeFromSync;
|
||||
}
|
||||
|
||||
public function setExcludeFromSync(bool $excludeFromSync): void
|
||||
{
|
||||
$this->excludeFromSync = $excludeFromSync;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?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\Core\Imaging\ImageManipulation;
|
||||
|
||||
use TYPO3\CMS\Core\Resource\FileInterface;
|
||||
|
||||
class CropVariantCollection
|
||||
{
|
||||
/**
|
||||
* @var CropVariant[]
|
||||
*/
|
||||
protected $cropVariants;
|
||||
|
||||
/**
|
||||
* @param CropVariant[] $cropVariants
|
||||
* @throws \TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException
|
||||
*/
|
||||
public function __construct(array $cropVariants)
|
||||
{
|
||||
$this->setCropVariants(...$cropVariants);
|
||||
}
|
||||
|
||||
public static function create(string $jsonString, array $tcaConfig = []): CropVariantCollection
|
||||
{
|
||||
$persistedCollectionConfig = empty($jsonString) ? [] : json_decode($jsonString, true);
|
||||
if (empty($persistedCollectionConfig) && empty($tcaConfig)) {
|
||||
return self::createEmpty();
|
||||
}
|
||||
try {
|
||||
if ($tcaConfig === []) {
|
||||
$tcaConfig = (array)$persistedCollectionConfig;
|
||||
} else {
|
||||
if (!is_array($persistedCollectionConfig)) {
|
||||
$persistedCollectionConfig = [];
|
||||
}
|
||||
// Merge selected areas with crop tool configuration
|
||||
reset($persistedCollectionConfig);
|
||||
foreach ($tcaConfig as $id => &$cropVariantConfig) {
|
||||
if (!isset($persistedCollectionConfig[$id])) {
|
||||
$id = key($persistedCollectionConfig);
|
||||
next($persistedCollectionConfig);
|
||||
}
|
||||
if (isset($persistedCollectionConfig[$id ?? '']['cropArea'])) {
|
||||
$cropVariantConfig['cropArea'] = $persistedCollectionConfig[$id]['cropArea'];
|
||||
}
|
||||
if (isset($persistedCollectionConfig[$id ?? '']['focusArea'], $cropVariantConfig['focusArea'])) {
|
||||
$cropVariantConfig['focusArea'] = $persistedCollectionConfig[$id]['focusArea'];
|
||||
}
|
||||
if (isset($persistedCollectionConfig[$id ?? '']['selectedRatio'], $cropVariantConfig['allowedAspectRatios'][$persistedCollectionConfig[$id ?? '']['selectedRatio']])) {
|
||||
$cropVariantConfig['selectedRatio'] = $persistedCollectionConfig[$id]['selectedRatio'];
|
||||
}
|
||||
}
|
||||
unset($cropVariantConfig);
|
||||
}
|
||||
$cropVariants = [];
|
||||
foreach ($tcaConfig as $id => $cropVariantConfig) {
|
||||
$cropVariants[] = CropVariant::createFromConfiguration($id, $cropVariantConfig);
|
||||
}
|
||||
return new self($cropVariants);
|
||||
} catch (\Throwable $throwable) {
|
||||
return self::createEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function asArray(): array
|
||||
{
|
||||
$cropVariantsAsArray = [];
|
||||
foreach ($this->cropVariants as $id => $cropVariant) {
|
||||
$cropVariantsAsArray[$id] = $cropVariant->asArray();
|
||||
}
|
||||
return $cropVariantsAsArray;
|
||||
}
|
||||
|
||||
public function applyRatioRestrictionToSelectedCropArea(FileInterface $file): CropVariantCollection
|
||||
{
|
||||
$newCollection = clone $this;
|
||||
foreach ($this->cropVariants as $id => $cropVariant) {
|
||||
$newCollection->cropVariants[$id] = $cropVariant->applyRatioRestrictionToSelectedCropArea($file);
|
||||
}
|
||||
return $newCollection;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$filterNonPersistentKeys = static function ($key) {
|
||||
if (in_array($key, ['id', 'title', 'allowedAspectRatios', 'coverAreas'], true)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
$cropVariantsAsArray = [];
|
||||
foreach ($this->cropVariants as $id => $cropVariant) {
|
||||
$cropVariantsAsArray[$id] = array_filter($cropVariant->asArray(), $filterNonPersistentKeys, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
return json_encode($cropVariantsAsArray) ?: '[]';
|
||||
}
|
||||
|
||||
public function getCropArea(string $id = 'default'): Area
|
||||
{
|
||||
if (isset($this->cropVariants[$id])) {
|
||||
return $this->cropVariants[$id]->getCropArea();
|
||||
}
|
||||
return Area::createEmpty();
|
||||
}
|
||||
|
||||
public function getFocusArea(string $id = 'default'): Area
|
||||
{
|
||||
if (isset($this->cropVariants[$id]) && $this->cropVariants[$id]->getFocusArea() !== null) {
|
||||
return $this->cropVariants[$id]->getFocusArea();
|
||||
}
|
||||
return Area::createEmpty();
|
||||
}
|
||||
|
||||
protected static function createEmpty(): CropVariantCollection
|
||||
{
|
||||
return new self([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException
|
||||
*/
|
||||
protected function setCropVariants(CropVariant ...$cropVariants)
|
||||
{
|
||||
$this->cropVariants = [];
|
||||
foreach ($cropVariants as $cropVariant) {
|
||||
$this->addCropVariant($cropVariant);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigurationException
|
||||
*/
|
||||
protected function addCropVariant(CropVariant $cropVariant)
|
||||
{
|
||||
if (isset($this->cropVariants[$cropVariant->getId()])) {
|
||||
throw new InvalidConfigurationException(sprintf('Crop variant with with duplicate ID (%s) is configured. Make sure all configured cropVariants have different ids.', $cropVariant->getId()), 1485284352);
|
||||
}
|
||||
$this->cropVariants[$cropVariant->getId()] = $cropVariant;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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\Core\Imaging\ImageManipulation;
|
||||
|
||||
/**
|
||||
* Thrown when an invalid TCA configuration for the image manipulation is detected
|
||||
*/
|
||||
class InvalidConfigurationException extends \Exception {}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?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\Core\Imaging\ImageManipulation;
|
||||
|
||||
class Ratio
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
public function __construct(string $id, string $title, float $value)
|
||||
{
|
||||
$this->id = self::prepareAspectRatioId($id);
|
||||
$this->title = $title;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust names of Ratios for special character replacement.
|
||||
*
|
||||
* @todo in 14 - Rework the ImageManipulationElement.fluid.html logic to actually allow dot keys.
|
||||
* Ratio names are referenced through fluid, see https://forge.typo3.org/issues/80214
|
||||
* Should be possible by iterating {cropVariant.allowedAspectRatios.{cropVariant.selectedRatio}.title}
|
||||
* in the controller, and assigning a distinct, un-nested variable.
|
||||
* This is a breaking change because then aspect ratios defined with a key
|
||||
* will be referred to differently and wouldn't be resolved as before. Probably a migration wizard
|
||||
* would be needed.
|
||||
*
|
||||
* @internal not part of TYPO3 Core API as this method might vanish soon.
|
||||
*/
|
||||
public static function prepareAspectRatioId(string $id): string
|
||||
{
|
||||
return str_replace('.', '_', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<Ratio>
|
||||
* @throws \TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException
|
||||
*/
|
||||
public static function createMultipleFromConfiguration(array $config): array
|
||||
{
|
||||
$areas = [];
|
||||
try {
|
||||
foreach ($config as $id => $ratioConfig) {
|
||||
$areas[] = new self(
|
||||
$id,
|
||||
(string)($ratioConfig['title'] ?? ''),
|
||||
(float)($ratioConfig['value'] ?? 0.0)
|
||||
);
|
||||
}
|
||||
} catch (\Throwable $throwable) {
|
||||
throw new InvalidConfigurationException(sprintf('Invalid type for ratio id given: %s', $throwable->getMessage()), 1486313971, $throwable);
|
||||
}
|
||||
return $areas;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @return array{id: string, title: string, value: float}
|
||||
*/
|
||||
public function asArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'value' => $this->value,
|
||||
];
|
||||
}
|
||||
|
||||
public function getRatioValue(): float
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function isFree(): bool
|
||||
{
|
||||
return $this->value === 0.0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user