You are here

public static function VolumeUnit::assertExists in Physical Fields 8

Asserts that the given unit exists.

Parameters

string $unit: The unit.

Throws

\InvalidArgumentException

Overrides UnitInterface::assertExists

1 call to VolumeUnit::assertExists()
VolumeUnit::getBaseFactor in src/VolumeUnit.php
Gets the base factor for the given unit.

File

src/VolumeUnit.php, line 73

Class

VolumeUnit
Provides volume units.

Namespace

Drupal\physical

Code

public static function assertExists($unit) {
  $allowed_units = [
    self::MILLILITER,
    self::CENTILITER,
    self::DECILITER,
    self::LITER,
    self::CUBIC_MILLIMETER,
    self::CUBIC_CENTIMETER,
    self::CUBIC_METER,
    self::CUBIC_INCH,
    self::CUBIC_FOOT,
    self::FLUID_OUNCE,
    self::US_GALLON,
  ];
  if (!in_array($unit, $allowed_units)) {
    throw new \InvalidArgumentException(sprintf('Invalid volume unit "%s" provided.', $unit));
  }
}