Beispiel #1
0
 /**
  * Formats number according to locale settings.
  *
  * Options format:
  * array(
  *     'attributes' => array(
  *          <attribute> => <value>,
  *          ...
  *      ),
  *     'textAttributes' => array(
  *          <attribute> => <value>,
  *          ...
  *      ),
  *     'symbols' => array(
  *          <symbol> => <value>,
  *          ...
  *      ),
  *     'locale' => <locale>
  * )
  *
  * @param int|float $value
  * @param int|string $style
  * @param array $options
  * @return string
  */
 public function format($value, $style, array $options = array())
 {
     $attributes = (array) $this->getOption($options, 'attributes', array());
     $textAttributes = (array) $this->getOption($options, 'textAttributes', array());
     $symbols = (array) $this->getOption($options, 'symbols', array());
     $locale = $this->getOption($options, 'locale');
     return $this->formatter->format($value, $style, $attributes, $textAttributes, $symbols, $locale);
 }
 /**
  * @param ValueRenderEvent $fieldValueEvent
  */
 public function beforeValueRender(ValueRenderEvent $fieldValueEvent)
 {
     $originalValue = $fieldValueEvent->getOriginalValue();
     $metadata = $fieldValueEvent->getMetadata();
     if ($originalValue instanceof AddressInterface) {
         $fieldValueEvent->setConvertedValue($this->addressFormatter->format($originalValue));
     } elseif ($originalValue instanceof NamePrefixInterface || $originalValue instanceof FirstNameInterface || $originalValue instanceof MiddleNameInterface || $originalValue instanceof LastNameInterface || $originalValue instanceof NameSuffixInterface) {
         $fieldValueEvent->setConvertedValue($this->nameFormatter->format($originalValue));
     } elseif ($originalValue instanceof \DateTime) {
         $dateType = $metadata->get('render_date_type');
         $timeType = $metadata->get('render_time_type');
         $dateTimePattern = $metadata->get('render_datetime_pattern');
         $fieldValueEvent->setConvertedValue($this->dateTimeFormatter->format($originalValue, $dateType, $timeType, null, null, $dateTimePattern));
     } elseif (is_numeric($originalValue)) {
         $numberStyle = $metadata->get('render_number_style');
         if (!$numberStyle) {
             $numberStyle = 'default_style';
         }
         $fieldValueEvent->setConvertedValue($this->numberFormatter->format($originalValue, $numberStyle));
     }
 }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage NumberFormatter style '19' is invalid
  */
 public function testFormatWithInvalidStyle()
 {
     $this->formatter->format(123, \NumberFormatter::LENIENT_PARSE);
 }