/** * {@inheritdoc} */ public function buildColumn(Column $column, $type, array $options = array()) { if ($column->hasHandler(self::NAME)) { return; } if (!isset($this->formatters[$type])) { throw FormatterException::notFound($type, array_keys($this->formatters)); } $column->register(new DataHandler($this->formatters[$type])); }
/** * {@inheritdoc} */ public function format($value, array $options = array()) { if (null === $value) { return $options['null_value']; } if (!is_numeric($value)) { throw FormatterException::invalidType($this, $value, 'numeric value'); } $formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL); if (null !== $options['precision']) { $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $options['precision']); $formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $options['rounding_mode']); } $formatter->setAttribute(\NumberFormatter::GROUPING_USED, $options['grouping']); $value = $formatter->format($value); if (intl_is_failure($formatter->getErrorCode())) { throw FormatterException::intlError($this, $formatter->getErrorMessage()); } return $value; }
/** * {@inheritdoc} */ public function format($value, array $options = array()) { if (null === $value) { return $options['null_value']; } if (!$value instanceof \DateTime) { throw FormatterException::invalidType($this, $value, 'DateTime instance'); } $dateTime = clone $value; if ('UTC' !== $options['time_zone']) { $dateTime->setTimezone(new \DateTimeZone('UTC')); } $formatter = new \IntlDateFormatter(\Locale::getDefault(), $options['date_format'], $options['time_format'], $options['time_zone'], $options['calendar'], $options['pattern']); $formatter->setLenient(false); $value = $formatter->format((int) $dateTime->format('U')); if (intl_is_failure(intl_get_error_code())) { throw FormatterException::intlError($this, intl_get_error_message()); } $value = preg_replace('~GMT\\+00:00$~', 'GMT', $value); return $value; }