‪TYPO3CMS  9.5
Ratio.php
Go to the documentation of this file.
1 <?php
2 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 
18 class ‪Ratio
19 {
23  protected ‪$id;
27  protected ‪$title;
31  protected ‪$value;
32 
33  public function ‪__construct(string ‪$id, string ‪$title, float ‪$value)
34  {
35  $this->id = str_replace('.', '_', ‪$id);
36  $this->title = ‪$title;
37  $this->value = ‪$value;
38  }
39 
43  public function ‪getId(): string
44  {
45  return ‪$this->id;
46  }
47 
53  public static function ‪createMultipleFromConfiguration(array $config): array
54  {
55  $areas = [];
56  try {
57  foreach ($config as ‪$id => $ratioConfig) {
58  $areas[] = new self(
59  ‪$id,
60  $ratioConfig['title'],
61  (float)$ratioConfig['value']
62  );
63  }
64  } catch (\Throwable $throwable) {
65  throw new ‪InvalidConfigurationException(sprintf('Invalid type for ratio id given: %s', $throwable->getMessage()), 1486313971, $throwable);
66  }
67  return $areas;
68  }
69 
74  public function ‪asArray(): array
75  {
76  return [
77  'id' => ‪$this->id,
78  'title' => ‪$this->title,
79  'value' => ‪$this->value,
80  ];
81  }
82 
86  public function ‪getRatioValue(): float
87  {
88  return ‪$this->value;
89  }
90 
94  public function ‪isFree(): bool
95  {
96  return $this->value === 0.0;
97  }
98 }
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\asArray
‪array asArray()
Definition: Ratio.php:71
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\isFree
‪bool isFree()
Definition: Ratio.php:91
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\getRatioValue
‪float getRatioValue()
Definition: Ratio.php:83
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\getId
‪string getId()
Definition: Ratio.php:40
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio
Definition: Ratio.php:19
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\$title
‪string $title
Definition: Ratio.php:25
‪TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException
Definition: InvalidConfigurationException.php:22
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\__construct
‪__construct(string $id, string $title, float $value)
Definition: Ratio.php:30
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\$id
‪string $id
Definition: Ratio.php:22
‪TYPO3\CMS\Core\Imaging\ImageManipulation
Definition: Area.php:3
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\createMultipleFromConfiguration
‪static Ratio[] createMultipleFromConfiguration(array $config)
Definition: Ratio.php:50
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio\$value
‪float $value
Definition: Ratio.php:28