‪TYPO3CMS  10.4
Ratio.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 class ‪Ratio
21 {
25  protected ‪$id;
29  protected ‪$title;
33  protected ‪$value;
34 
35  public function ‪__construct(string ‪$id, string ‪$title, float ‪$value)
36  {
37  $this->id = str_replace('.', '_', ‪$id);
38  $this->title = ‪$title;
39  $this->value = ‪$value;
40  }
41 
45  public function ‪getId(): string
46  {
47  return ‪$this->id;
48  }
49 
55  public static function ‪createMultipleFromConfiguration(array $config): array
56  {
57  $areas = [];
58  try {
59  foreach ($config as ‪$id => $ratioConfig) {
60  $areas[] = new self(
61  ‪$id,
62  $ratioConfig['title'],
63  (float)$ratioConfig['value']
64  );
65  }
66  } catch (\Throwable $throwable) {
67  throw new ‪InvalidConfigurationException(sprintf('Invalid type for ratio id given: %s', $throwable->getMessage()), 1486313971, $throwable);
68  }
69  return $areas;
70  }
71 
76  public function ‪asArray(): array
77  {
78  return [
79  'id' => ‪$this->id,
80  'title' => ‪$this->title,
81  'value' => ‪$this->value,
82  ];
83  }
84 
88  public function ‪getRatioValue(): float
89  {
90  return ‪$this->value;
91  }
92 
96  public function ‪isFree(): bool
97  {
98  return $this->value === 0.0;
99  }
100 }
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\asArray
‪array asArray()
Definition: Ratio.php:73
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\isFree
‪bool isFree()
Definition: Ratio.php:93
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\getRatioValue
‪float getRatioValue()
Definition: Ratio.php:85
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\getId
‪string getId()
Definition: Ratio.php:42
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio
Definition: Ratio.php:21
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\$title
‪string $title
Definition: Ratio.php:27
‪TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException
Definition: InvalidConfigurationException.php:24
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\__construct
‪__construct(string $id, string $title, float $value)
Definition: Ratio.php:32
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\$id
‪string $id
Definition: Ratio.php:24
‪TYPO3\CMS\Core\Imaging\ImageManipulation
Definition: Area.php:18
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\createMultipleFromConfiguration
‪static Ratio[] createMultipleFromConfiguration(array $config)
Definition: Ratio.php:52
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\$value
‪float $value
Definition: Ratio.php:30