|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
-
-
- namespace domain\Config\Unit;
-
- use domain\_\AbstractSolver;
-
- class UnitSolver extends AbstractSolver
- {
- protected UnitDefinition $unitDefinition;
-
- public function loadDependencies(): void
- {
- $this->unitDefinition = $this->loadService(UnitDefinition::class);
- }
-
- public function getUnit(string $idUnit): ?array
- {
- $unitsArray = $this->unitDefinition->getUnits();
- if(isset($unitsArray[$idUnit])) {
- return $unitsArray[$idUnit];
- }
-
- return null;
- }
-
-
- public function getUnitReference(string $idUnit): string
- {
- $unit = $this->getUnit($idUnit);
-
- if ($unit && isset($unit['ref_unit'])) {
- return $unit['ref_unit'];
- }
-
- return $idUnit;
- }
-
- public function getUnitCoefficient(string $idUnit): int
- {
- $unit = $this->getUnit($idUnit);
-
- if($unit) {
- return $unit['coefficient'];
- }
-
- return 1;
- }
-
-
-
- public function strUnit(string $idUnit, $format = UnitDefinition::WORDING_SHORT, bool $unitReference = false): string
- {
- if ($unitReference) {
- $idUnit = $this->getUnitReference($idUnit);
- }
-
- $unit = $this->getUnit($idUnit);
- if ($unit && isset($unit[$format])) {
- return $unit[$format];
- }
-
- return '';
- }
- }
|