‪TYPO3CMS  ‪main
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 
42  public function getId(): string
43  {
44  return $this->id;
45  }
46 
51  public static function createMultipleFromConfiguration(array $config): array
52  {
53  $areas = [];
54  try {
55  foreach ($config as $id => $ratioConfig) {
56  $areas[] = new self(
57  $id,
58  (string)($ratioConfig['title'] ?? ''),
59  (float)($ratioConfig['value'] ?? 0.0)
60  );
61  }
62  } catch (\Throwable $throwable) {
63  throw new InvalidConfigurationException(sprintf('Invalid type for ratio id given: %s', $throwable->getMessage()), 1486313971, $throwable);
64  }
65  return $areas;
66  }
67 
73  public function asArray(): array
74  {
75  return [
76  'id' => $this->id,
77  'title' => $this->title,
78  'value' => $this->value,
79  ];
80  }
81 
82  public function getRatioValue(): float
83  {
84  return $this->value;
85  }
86 
87  public function isFree(): bool
88  {
89  return $this->value === 0.0;
90  }
91 }
‪TYPO3\CMS\Core\Imaging\ImageManipulation
Definition: Area.php:18