-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.3] Added currency locale data, form type and validator #6566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Big 👍 for this. Thanks @mvrhov! |
BTW: I have no idea why the php 5.3.x seg'faults when running tests on Travis. |
public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
{ | ||
$resolver->setDefaults(array( | ||
'choices' => Locale::getDisplayCurrencies(\Locale::getDefault()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should probably be:
'choices' => Locale::getDisplayCurrencies(Locale::getDefault()),
(use Symfony's Locale consistently)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All other types: Country, Language, Locale, Date, Money.. also use the one from main ns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I won't argue ;)
I still think we should use Symfony's Locale class. However, it should be used everywhere consistently (so if we're about to fix it, we should fix it in other types as well).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakzal It doesn't really matter which of the two you use. If you think it is better, you can create a PR that fixes appearances of \Locale::get|setDefault to Symfony's equivalent.
@fabpot: Any chances of having this in 2.2? I really need this in my next project and I would be a shame if I had to maintain a 2.2 fork just because of this feature |
👍 |
/** | ||
* Validates whether a value is a valid locale code | ||
* | ||
* @author Bernhard Schussek <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the truth is that the file is almost identical to other locale based validators. So basically I'm the author of the few lines that are different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok that you are the author.
To me the author is the one who had the idea/designed it conceptually or contributed large parts of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mvrhov it's your decision :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still you have edited the file, so you should at least add yourself as author (there can be more than one author).
Big 👍 |
use Symfony\Component\Locale\Locale; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
|
||
class CurrencyType extends AbstractType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
phpdoc missing
Looks good apart from a few minor issues! |
* | ||
* @throws \RuntimeException When the resource bundles cannot be loaded | ||
*/ | ||
public static function getDisplayCurrencies($locale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds strange. Why not getCurrencyNames
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see it's because \Locale
also uses getDisplay...
.
This has been implemented as a part of #7386 |
Ok, I'll reopen and rebase this later today. |
This is now rebased |
use Symfony\Component\Intl\Intl; | ||
use Symfony\Component\Locale\Locale; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing doc block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bschussek All form types are without it. do you still want me to add it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad examples are still bad examples :)
Thank you @mvrhov! :) 👍 |
use Symfony\Component\Validator\Exception\UnexpectedTypeException; | ||
|
||
/** | ||
* Validates whether a value is a valid locale code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: locale -> currency
Please let me know before merging so I can cherry pick this on master and do a clean PR. |
Looks good :) Not sure what you mean with your last comment, but do whatever you feel is necessary! |
@mvrhov As you squashed your commits, I think there are no problems with the old data. |
This PR was merged into the master branch. Discussion ---------- [2.3] Added currency locale data, form type and validator Bug fix: no Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: yes License of the code: MIT Documentation PR: symfony/symfony-docs#2105 Commits ------- 5609aae Added currency form type and validator
Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT
Documentation PR: symfony/symfony-docs#2105