phone-number-bundle icon indicating copy to clipboard operation
phone-number-bundle copied to clipboard

[FEATURE] Ability to choose a getter for the region

Open Neirda24 opened this issue 7 years ago • 25 comments

The goal is to be able to dynamically choose the region via regionProperty. Use:

use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;

/**
 * @AssertPhoneNumber(defaultRegion="GB", regionProperty="regionCode")
 */
private $phoneNumber;

/**
 * @var string
 */
private $regionCode;

/**
 * @return string
 */
public function getRegionCode()
{
    return $this->regionCode;
}

Neirda24 avatar Oct 01 '16 13:10 Neirda24

I think you should rather make it possible to attach this constraint not only to constraints, but also to getter methods like it is done for most of the core validation constraints (see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/Blank.php#L18 for an example).

xabbuh avatar Oct 11 '16 18:10 xabbuh

@xabbuh : I'm not sure exactly about what you would like. You want me to create a dedicated annotation for getter / setter ? because in this case the getter is really specific to the logic in the validator.

Neirda24 avatar Oct 11 '16 20:10 Neirda24

@Neirda24 Sorry, I misread your PR.

However, looking at what you would like to achieve, wouldn'it be better to allow to pass a property path (rather than a method name) or even an expression here? That would be a bit more flexible imo.

xabbuh avatar Oct 11 '16 20:10 xabbuh

@xabbuh with the PropertyAccessor you mean ? It is a very good idea. However it will add a new dependency to the composer.json

Neirda24 avatar Oct 11 '16 20:10 Neirda24

@Neirda24 Well, you could make that dependency optional and throw an exception if the constraint is configured with a property path while the component is not available. However, I don't think that adding this dependency would be a big problem. In most Symfony projects, it's present already anyway.

xabbuh avatar Oct 11 '16 21:10 xabbuh

@xabbuh : I agree. I will do it this way then.

Neirda24 avatar Oct 11 '16 21:10 Neirda24

@xabbuh : this should do it.

Neirda24 avatar Oct 11 '16 21:10 Neirda24

@meeprophone , @NMattin , @rh389 , @StuBez : Hi. What is missing for it to be merged ? Thank you.

Neirda24 avatar Oct 17 '16 20:10 Neirda24

Thanks for this. I'm not an active maintainer but at a glance the tests are failing because context->getObject() was only added in symfony/validator 2.5, and this bundle currently supports ~2.1. @thewilkybarkid might be open to bumping up that requirement? I can't see an obvious workaround.

A couple of other comments:

  • path is a bit too general as a name - regionProperty maybe?
  • Test coverage and a mention of the new option in the README would be good.

robhogan avatar Oct 18 '16 17:10 robhogan

@rh389 : Thank you for your reply. I'll take a look at what you said. I'll try also to find a quick workaround for context->getObject()but as you said none is obvious...

Neirda24 avatar Oct 18 '16 19:10 Neirda24

@rh389 : All is green. I upgraded, as you suggested, the minimum version required for the symfony validator.

Is it possible to merge it ?

Neirda24 avatar Oct 26 '16 17:10 Neirda24

@thewilkybarkid : Any comments on this or is it possible to merge it ?

Neirda24 avatar Nov 22 '16 14:11 Neirda24

@thewilkybarkid : Any news ?

Neirda24 avatar Mar 07 '17 14:03 Neirda24

@meeprophone , @NMattin , @rh389 , @StuBez : Hi. What is missing for it to be merged ? Thank you.

Neirda24 avatar Mar 22 '17 09:03 Neirda24

@xabbuh @meeprophone , @NMattin , @rh389 , @StuBez : Hi. What is missing for it to be merged ? Thank you. Anyone ?

Neirda24 avatar May 03 '17 09:05 Neirda24

@Neirda24 Afaik @rh389 needs to make the decision as he is the main maintainer of this bundle now.

xabbuh avatar May 03 '17 09:05 xabbuh

I'm not a maintainer - I'll help out where I can (reviews, merging trivial PRs) but I don't even work with PHP any more!

I'll be seeing @thewilkybarkid this week, will have a chat with him about bringing some other people in, or if there's anything else we can do to revive the maintenance of this project.

(@Neirda24 - thanks for your patience. Sorry this has been idle so long.)

robhogan avatar May 03 '17 12:05 robhogan

If the current maintainer is not willing to continue, I suggest to open an issue and look for new ones (preferably more than one). I am personally too busy with other projects but I am sure we can find volunteers.

skafandri avatar May 03 '17 12:05 skafandri

@rh389 I am doing some helping checking the issues and doing reviews. I appreciate the time that you spend, hopefully some people like me would help you a bit. This PR only remains the merge or you want add some comment more or changes?

shakaran avatar Sep 01 '17 19:09 shakaran

This looks exactly like what I need and it looks ready to be merged to me?

Toflar avatar Nov 01 '17 11:11 Toflar

@shakaran , @rh389 : Any news how we can get this done ?

Neirda24 avatar Nov 07 '17 12:11 Neirda24

@Neirda24 if you want please rebase the conflicts in README.md, so it would be prepared to merge when the maintainers could have a bit of time on this issue

shakaran avatar Nov 07 '17 12:11 shakaran

@shakaran : Done ;)

Neirda24 avatar Nov 07 '17 12:11 Neirda24

@Neirda24 thanks, just remain that the maintainers find a little spare time to check this, sorry I cannot help more since I don't have merge permissions in this repo

shakaran avatar Nov 07 '17 12:11 shakaran

If you want, you can redirect your PR to this repo : https://github.com/odolbeau/phone-number-bundle We would be happy to merge this :)

maxhelias avatar Nov 28 '19 13:11 maxhelias