-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RFC] [Validator] adding a new WordCount constraint validator #6813
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
Comments
-1 for a lot of reasons but the main two are:
|
I was expecting the too specific need argument. That's why I also opened the PR to know more about the community comments. Defining what a word is, is tricky I guess. I was thinking of using the native
I guess it only works with latin alphabets. I don't know if it works with languages like Chinese or Russian. |
This is going to be off-topic, sorry. They should be compatible with the currently active versions of Symfony2 and would help creating various validators and sharing them with other users without touching the main repository? If I've missed the reason for it, sorry, just tell me to look for it and I'll do. |
It's true that the proposed constraint seems too specific, but in my opinion Symfony already includes some very specific (and perhaps not used much) constraints such as About the "What is a word?" consideration, this is of course a problem impossible to solve, but there are some good-enough solutions. Besides the
Last but not least, keep in mind that the word constraint is absolutely mandatory for journalists, professional bloggers and other technical writers. These people use CMS tools and Symfony is the technology selected by lots of CMS-related projects (Drupal, Symfony CMF, eZ Publish, Fork CMS, etc.) |
As mentionned @dlsniper, a policy about *Extensions repositories would be welcome. There are currently: An more or less official FormExtensions would be great and some publicity about these extensions from symfony.com or other, would be even better. |
Closing as I fear we won't agree of what a word is. |
ICU / Intl is providing a breakIterator to detect words / sentences etc: https://unicode-org.github.io/icu/userguide/boundaryanalysis/#word-boundary So we don't have to agree on what a word is, that's not for Symfony to decide. We can leverage the BreakIterator like this: <?php
function getWords(string $content)
{
$bi = \IntlBreakIterator::createWordInstance();
$bi->setText($content);
$words = iterator_to_array($bi->getPartsIterator());
$words = array_map('trim', $words);
return array_values(array_filter($words));
}
var_dump(getWords('次のバスは遠いです')); // Expected 6
var_dump(getWords('Ton père je suis !')); // Expected 5 So I would like to suggest we reopen this issue to explore this path, maybe even add a method in the String component? Thanks! |
Hi, I'm new to contributing to symfony, but work with it daily. We use word count for limiting paper abstract sizes and such. I don't think this validator is too specific and with the I offer to help. |
Yeah I dont think 'too specific' can be a valid argument anymore, when we have Bic, ISBN, etc |
implemented in #57716 |
Hi guys,
I was thinking of adding a new constraint validator similar to the
Length
constraint but for counting words in a string. Sometimes, when writing a text or a description, we're asked to write at least x words or at most x words.Do you think it would be needed in the validator component?
The text was updated successfully, but these errors were encountered: