/** * Given a unit of measure, determine if its name or any of its aliases conflict * with the set of already-known unit names and aliases. * * @param UnitOfMeasureInterface $unit The unit in question * * @return boolean true if there is a conflict, false if there is not */ protected static function unitNameOrAliasesAlreadyRegistered(UnitOfMeasureInterface $unit) { // If this class hasn't been initialized yet, do so now if (!is_array(static::$unitDefinitions)) { static::$unitDefinitions = []; static::initialize(); } $currentUnitNamesAndAliases = []; foreach (static::$unitDefinitions as $unitOfMeasure) { $currentUnitNamesAndAliases[] = $unitOfMeasure->getName(); $currentUnitNamesAndAliases = array_merge($currentUnitNamesAndAliases, $unitOfMeasure->getAliases()); } $newUnitNamesAndAliases = array_merge([$unit->getName()], $unit->getAliases()); return count(array_intersect($currentUnitNamesAndAliases, $newUnitNamesAndAliases)) > 0; }
/** * Convert this quantity to the given unit of measure. * * @param UnitOfMeasureInterface $unit The object representing the target unit of measure. * * @return PhysicalQuantity This quantity's value in the given unit of measure. */ private function toUnitOfMeasure(UnitOfMeasureInterface $unit) { $thisValueInNativeUnit = $this->toNativeUnit()->getValue(); return new static($unit->convertValueFromNativeUnitOfMeasure($thisValueInNativeUnit), $unit->getName()); }