TYPO3 CMS  TYPO3_8-7
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 }
__construct(string $id, string $title, float $value)
Definition: Ratio.php:33
static createMultipleFromConfiguration(array $config)
Definition: Ratio.php:53