Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Introduce Zend\I18n\Filter\NumberParse based on Zend\I18n\Filter\NumberFormat #4510

Closed

Conversation

localheinz
Copy link
Member

This PR is related to #4493 and replaces #4495 and introduces Zend\I18n\Filter\NumberParse which filters a string parseable by NumberFormatter to a number.

Ping @cgmartin.

@localheinz
Copy link
Member Author

Credits for the code and tests should go to @cgmartin because everything is just based on Zend\I18n\Filter\NumberFormat.

@cgmartin
Copy link
Contributor

Actually, @denixport gets the credit as original author. I'm just a curious bystander. :)

Also, see my comments in #4495 . Thanks!

@denixport
Copy link
Contributor

I think that initially dual behavior of the filter was bad Idea of mine. But no way to change it because of BC.

So separate filter seems like good idea, just few notes:

  • keep ICU naming scheme: format/parse, so \NumberFormat does formatting of numeric value to string and NumberParse parses locale formatted string into int/double
  • there should be note in docs that parsing behavior of NumberFormat is discouraged or even deprecated
  • addition of DateFormat and DateParse filters (relatively easy to implement) will help to make clear that formatter and parser are separate filters

@localheinz
Copy link
Member Author

@denixport Thanks for your suggestion, I will take care of it!

Got a question though: Do you think it will make more sense to change the order of inheritance? The NumberFormat filter could extend the NumberParse filter - if a number could be parsed from the string, it can be easily formatted to whatever is desired.

@localheinz
Copy link
Member Author

@denixport For consistency reasons, either DateTimeFormatter should be called DateTimeFormat- or NumberFormat should be called NumberFormatter, then, no?

@denixport
Copy link
Contributor

@localheinz

  • on inheritance, I agree, makes sense
  • on naming consistency, by the time this filter was created we already had Zend\I18n\View\Helper\NumberFormat & DateFormat, so I just kept it consistent with view helpers, and I think it's better to keep that way

* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_I18n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove @Package

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

public function filter($value)
{
if (!is_int($value)
|| !is_float($value)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be &&.

$formatter = $this->getFormatter();
$type = $this->getType();
if (!is_int($value)
&& !is_float($value)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closing paren and opening brace on next line, please:

if (!is_int($value)
    && !is_float($value)
) {

@ghost ghost assigned weierophinney May 23, 2013
weierophinney added a commit that referenced this pull request May 23, 2013
Introduce Zend\I18n\Filter\NumberParse based on Zend\I18n\Filter\NumberFormat
weierophinney added a commit that referenced this pull request May 23, 2013
@weierophinney
Copy link
Member

Merged to develop for release with 2.3.0.

weierophinney added a commit that referenced this pull request May 23, 2013
- Move closing paren/opening brace to next line
  - constructor (multi-line definition)
  - if statement (multi-line conditional)
localheinz added a commit to localheinz/zf2-documentation that referenced this pull request May 28, 2013
weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
…eature/number-filter

Introduce Zend\I18n\Filter\NumberParse based on Zend\I18n\Filter\NumberFormat
weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
- Move closing paren/opening brace to next line
  - constructor (multi-line definition)
  - if statement (multi-line conditional)
weierophinney added a commit to zendframework/zend-filter that referenced this pull request May 15, 2015
…eature/number-filter

Introduce Zend\I18n\Filter\NumberParse based on Zend\I18n\Filter\NumberFormat
weierophinney added a commit to zendframework/zend-filter that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants