2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-10-02 11:38:11 +01:00
|
|
|
*
|
2010-06-24 09:40:05 +01:00
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-06-24 09:40:05 +01:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\Form;
|
|
|
|
|
2010-10-02 11:38:11 +01:00
|
|
|
use Symfony\Component\Form\ValueTransformer\NumberToLocalizedStringTransformer;
|
|
|
|
|
2010-06-24 09:40:05 +01:00
|
|
|
/**
|
|
|
|
* A localized field for entering numbers.
|
|
|
|
*
|
2011-01-21 18:04:20 +00:00
|
|
|
* Available options:
|
|
|
|
*
|
|
|
|
* * precision: The number of digits to allow when rounding. Default
|
|
|
|
* is locale-specific.
|
|
|
|
* * grouping:
|
|
|
|
* * rounding-mode: The method to use to round to get to the needed level
|
|
|
|
* of precision. Options include:
|
|
|
|
* * NumberToLocalizedStringTransformer::ROUND_FLOOR
|
|
|
|
* * NumberToLocalizedStringTransformer::ROUND_DOWN
|
|
|
|
* * NumberToLocalizedStringTransformer::ROUND_HALFDOWN
|
|
|
|
* * NumberToLocalizedStringTransformer::ROUND_HALFUP (default)
|
|
|
|
* * NumberToLocalizedStringTransformer::ROUND_UP
|
|
|
|
* * NumberToLocalizedStringTransformer::ROUND_CEILING
|
|
|
|
*
|
|
|
|
* @see \NumberFormatter
|
2010-06-24 09:40:05 +01:00
|
|
|
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
|
|
|
*/
|
2010-11-15 11:57:41 +00:00
|
|
|
class NumberField extends Field
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
// default precision is locale specific (usually around 3)
|
|
|
|
$this->addOption('precision');
|
|
|
|
$this->addOption('grouping', false);
|
2010-09-24 19:35:34 +01:00
|
|
|
$this->addOption('rounding-mode', NumberToLocalizedStringTransformer::ROUND_HALFUP);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-11-12 06:53:25 +00:00
|
|
|
parent::configure();
|
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->setValueTransformer(new NumberToLocalizedStringTransformer(array(
|
|
|
|
'precision' => $this->getOption('precision'),
|
|
|
|
'grouping' => $this->getOption('grouping'),
|
2010-09-24 19:35:34 +01:00
|
|
|
'rounding-mode' => $this->getOption('rounding-mode'),
|
2010-06-24 10:24:08 +01:00
|
|
|
)));
|
|
|
|
}
|
2010-10-02 11:38:11 +01:00
|
|
|
}
|