Skip to content

[Form] add guess pattern #3927

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

Merged
merged 0 commits into from
Apr 23, 2012
Merged

[Form] add guess pattern #3927

merged 0 commits into from
Apr 23, 2012

Conversation

ruian
Copy link
Contributor

@ruian ruian commented Apr 13, 2012

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #3766
Todo: -

@stloyd
Copy link
Contributor

stloyd commented Apr 13, 2012

You need to revert change of permissions.

@@ -16,6 +16,7 @@
Copy link
Member

Choose a reason for hiding this comment

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

please revert all permission changes

@vicb
Copy link
Contributor

vicb commented Apr 13, 2012

Some file permissions have been changed in your commit, they should be reverted

@@ -68,6 +68,13 @@ public function guessMinLength($class, $property)
});
}

public function guessPattern($class, $property)
Copy link
Contributor

Choose a reason for hiding this comment

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

You should add {@inheritDoc}.

@ruian
Copy link
Contributor Author

ruian commented Apr 13, 2012

What do you mean by "please revert all permission changes" because i did not change any permissions by myself :/

@stof
Copy link
Member

stof commented Apr 13, 2012

@ruian which OS are you using ? If you are on windows, you should configure git to ignore file permissions (as Windows cannot handle them). Msysgit should do it by default but some other tools don't configure git this way: http://stackoverflow.com/questions/6476513/git-file-permissions-on-windows-7

@ruian
Copy link
Contributor Author

ruian commented Apr 13, 2012

@stof i'm on linux but i did not change any chmod or chown since a clone the repo

@stof
Copy link
Member

stof commented Apr 13, 2012

@ruian In your pull request, you are changing file permissions from 644 to 755. This is what should be reverted

public function guessPatternForConstraint(Constraint $constraint)
{
switch (get_class($constraint)) {
case 'Symfony\Component\Validator\Constraints\MaxLength':
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you mean Regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@stof
Copy link
Member

stof commented Apr 13, 2012

Can you squash your commits ?

@ruian
Copy link
Contributor Author

ruian commented Apr 13, 2012

you mean rebase ? If it the case i have never test

@jalliot
Copy link
Contributor

jalliot commented Apr 13, 2012

Look at the doc at the end of the page ;)

@ruian
Copy link
Contributor Author

ruian commented Apr 13, 2012

Yep i will look at it

@ruian
Copy link
Contributor Author

ruian commented Apr 13, 2012

@stof I squash my commits. It's ok ?

@stof
Copy link
Member

stof commented Apr 13, 2012

It looks good to me. @fabpot @bschussek ready for the final review

@ruian could you send PRs to https://github.com/doctrine/DoctrineMongoDBBundle https://github.com/doctrine/DoctrinePHPCRBundle and https://github.com/doctrine/DoctrineCouchDBBundle to add the new method ?

@ruian
Copy link
Contributor Author

ruian commented Apr 13, 2012

yep sure


$type = $typeGuess ? $typeGuess->getType() : 'text';

$maxLength = $maxLengthGuess ? $maxLengthGuess->getValue() : null;
$minLength = $minLengthGuess ? $minLengthGuess->getValue() : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is wrong... as getValue() can return null. Could you revert and add a comment here (which I should have done in first place).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep sure i revert it as you wish

Copy link
Member

Choose a reason for hiding this comment

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

it is needed as you code is broken in case of a null value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's fixed now, i will squash and make some PR into others Repo who depends of this

@ruian
Copy link
Contributor Author

ruian commented Apr 13, 2012

@stof I made all Doctrine PRs to respect this new one

@ruian
Copy link
Contributor Author

ruian commented Apr 16, 2012

@bschussek any comments on this PR ?

{
switch (get_class($constraint)) {
case 'Symfony\Component\Validator\Constraints\Regex':
return new PatternGuess($constraint->pattern, Guess::LOW_CONFIDENCE);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use ValueGuess instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

You should put MEDIUM_CONFIDENCE here. A second case statement should be added for the MinLength constraint. If you check FormFactory, a "pattern" constraint is created there for min length - these two functionalities must now be merged.

@webmozart
Copy link
Contributor

Hi @ruian, thank you for the PR! I added some comments and hope you can check them soon. If you need help, just drop a message.

@ruian
Copy link
Contributor Author

ruian commented Apr 17, 2012

@bschussek thx for your comments, i will do this as soon as possible

@ruian
Copy link
Contributor Author

ruian commented Apr 18, 2012

@bschussek should i remove all call to guessMinLength ?

{
switch (get_class($constraint)) {
case 'Symfony\Component\Validator\Constraints\Regex':
return new ValueGuess($constraint->pattern, Guess::MEDIUM_CONFIDENCE );
Copy link
Contributor

Choose a reason for hiding this comment

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

The pattern for the MinLength constraint should be added here as well (with LOW_CONFIDENCE).

@webmozart
Copy link
Contributor

@ruian Yes, guessMinLength() can be removed entirely (and all references to it).

@ruian
Copy link
Contributor Author

ruian commented Apr 20, 2012

ping @bschussek is it good like this ?

{
$guesser = $this;

return $this->guess($class, $property, function (Constraint $constraint) use ($guesser) {
return $guesser->guessMinLengthForConstraint($constraint);
return $guesser->guessPatternConstraint($constraint);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep the "For" in the method name.

@ruian
Copy link
Contributor Author

ruian commented Apr 21, 2012

@bschussek @vicb i think it's good now, and i think i understood the diff between Size and SizeLength Constraint ValueGuess (One is for numeric and the other for string). It was not clear in my mind when i made the change. But now it's okay

* @param string $class The fully qualified class name
* @param string $property The name of the property to guess for
*
* @return Guess The guess for the pattern
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the comment to FormTypeGuesserInterface and use {@inheritdoc} in all implementing classes.

@webmozart
Copy link
Contributor

Please squash the commits once you're done. You should also update the CHANGELOG.

@ghost
Copy link

ghost commented Apr 22, 2012

This needs to be rebased with also as it currently wont merge. (git fetch; git rebase origin/master).

@ruian ruian merged commit b0a6956 into symfony:master Apr 23, 2012
@lsmith77
Copy link
Contributor

something is strange with this PR .. why is it marked as merged by @ruian? and why are there no changes in the diff? and why was it labeled as no BC break?

@ruian
Copy link
Contributor Author

ruian commented Apr 23, 2012

@lsmith77 I don't know, what append, i merge the master into my branch...
So a recreate a PR #4077 but it seems alright now.

@webmozart
Copy link
Contributor

@lsmith77 You are right, this should be marked as BC break. I originally thought that guessMinLength() was only introduced after 2.0, but it was not. I will update the documentation.

@ruian
Copy link
Contributor Author

ruian commented Apr 23, 2012

@bschussek do you want i create a new PR for the changelog ?

@webmozart
Copy link
Contributor

@ruian I already did this. Thanks anyway!

fabpot added a commit that referenced this pull request Apr 23, 2012
Commits
-------

d9e142b [Form] Restored and deprecated method `guessMinLength` in FormTypeGuesser

Discussion
----------

[Form] Restored and deprecated method `guessMinLength` in FormTypeGuesser

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue4077)

This is a follow-up PR to #4077 (see comments in #3927 for reference).
craigmarvelley pushed a commit to craigmarvelley/symfony that referenced this pull request Nov 26, 2013
Commits
-------

f7200e4 [Form] added method `guessPattern` to FormTypeGuesserInterface

Discussion
----------

[Form] add guess pattern

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: symfony#3766
Todo: -

Due to some trouble when rebase my previous PR i open a new one with Master merged
Refs PR: symfony#3927

---------------------------------------------------------------------------

by fabpot at 2012-04-23T10:25:57Z

@vicb @bschussek ok for you?

---------------------------------------------------------------------------

by bschussek at 2012-04-23T10:26:51Z

please do also rephrase the commit message to something clearer, like

    [Form] added method `guessPattern` to FormTypeGuesserInterface

---------------------------------------------------------------------------

by bschussek at 2012-04-23T10:27:35Z

Otherwise this looks good :)

---------------------------------------------------------------------------

by ruian at 2012-04-23T10:29:18Z

every changes done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Form Good first issue Ideal for your first contribution! (some Symfony experience may be required)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants