/** * Formats a value. * * @since 0.1 * * @param mixed $value The value to format * * @return string The formatted value (as wikitext). * @throws FormattingException */ public function format($value) { if (is_int($value) || is_float($value)) { return $this->valueLocalizer->localizeNumber($value); } elseif ($value instanceof DataValue) { return $this->dataValueFormatter->format($value); } elseif (is_object($value)) { return $this->formatObject($value); } elseif (is_array($value)) { return $this->formatValueList($value); } return wfEscapeWikiText(strval($value)); }
/** * @see ValueFormatter::format * * @since 0.1 * * @param DecimalValue $dataValue * * @throws InvalidArgumentException * @return string Text */ public function format($dataValue) { if (!$dataValue instanceof DecimalValue) { throw new InvalidArgumentException('Data value type mismatch. Expected a DecimalValue.'); } // TODO: Implement optional rounding/padding $decimal = $dataValue->getValue(); if (!$this->getOption(self::OPT_FORCE_SIGN)) { // strip leading + $decimal = ltrim($decimal, '+'); } // apply number localization $decimal = $this->localizer->localizeNumber($decimal); return $decimal; }