final class TemperatureUnit in Physical Fields 8
Provides common temperature units.
Hierarchy
- class \Drupal\physical\TemperatureUnit implements UnitInterface
Expanded class hierarchy of TemperatureUnit
File
- src/
TemperatureUnit.php, line 8
Namespace
Drupal\physicalView source
final class TemperatureUnit implements UnitInterface {
const KELVIN = 'K';
const CELSIUS = 'C';
const FAHRENHEIT = 'F';
/**
* {@inheritdoc}
*/
public static function getLabels() {
return [
self::KELVIN => t('K'),
self::CELSIUS => t('°C'),
self::FAHRENHEIT => t('°F'),
];
}
/**
* {@inheritdoc}
*/
public static function getBaseUnit() {
return self::CELSIUS;
}
/**
* {@inheritdoc}
*/
public static function getBaseFactor($unit) {
self::assertExists($unit);
// Not used, see Temperature::convert().
$factors = [
self::KELVIN => '274.15',
self::CELSIUS => '1',
self::FAHRENHEIT => '33.8',
];
return $factors[$unit];
}
/**
* {@inheritdoc}
*/
public static function assertExists($unit) {
$allowed_units = [
self::KELVIN,
self::CELSIUS,
self::FAHRENHEIT,
];
if (!in_array($unit, $allowed_units)) {
throw new \InvalidArgumentException(sprintf('Invalid temperature unit "%s" provided.', $unit));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TemperatureUnit:: |
public static | function |
Asserts that the given unit exists. Overrides UnitInterface:: |
|
TemperatureUnit:: |
constant | |||
TemperatureUnit:: |
constant | |||
TemperatureUnit:: |
public static | function |
Gets the base factor for the given unit. Overrides UnitInterface:: |
|
TemperatureUnit:: |
public static | function |
Gets the base unit. Overrides UnitInterface:: |
|
TemperatureUnit:: |
public static | function |
Gets the labels for the defined units. Overrides UnitInterface:: |
|
TemperatureUnit:: |
constant |