-
Notifications
You must be signed in to change notification settings - Fork 356
Update StringConstraint.php #220
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
- Regex limitations removed because of starting and ending # - add-et @preg_match to avoid regex notices and warnings This will allow developers to create more complicated regex patterns for example #u as usage of Unicode ... only extra work in Schema is to supply pattern with starting and ending #
@xMolchy please review the Travis build. Several tests are now failing per these changes. For the regex flexibility you are trying to achieve, is there another JSON Schema validator implementation out there that provides what you are looking for? I am wondering if the changes you are trying to contribute are aligned with the JSON Schema spec. |
@bighappyface Did research and yes you are right it does not fallow any JSON Schema standard, so changes made can be ignored. Sorry for made mistakes (Working to much and rushing things ;) ). Thing you can do is leave @preg_match so server will not pop out warnings and notices. This i write for those that wishes to use UNICODE in their patterns (For example Arabic, Chinese ... ) If you specify (*UTF8) in regex then input-ed string will be encoded correctly. They say there is another option but has to be compiled on the server .... THIS WILL CHECK CHARS, NUM AND DASH: *'#(UTF8)^[0-9\p{L}\p{Pd}\p{N}]+$#' and |
@xMolchy thanks for checking into the spec and spending more time on this. I think leaving the In reviewing the code a bit further I believe the best course of action is to provide more flexibility in customizing constraint behavior. As I see it, modifying I have opened #221 to provide such behavior. Please review it and let me know if that will help you achieve the custom behavior you need without modifying the base constraint. |
Looks good, will not break Schema standard and if someone wishes to extend constraints, add extra format support and make new constraint he can do that now ... great job!!! First thing i tried was extend but failed (too many dependencies) ;) because sometime you have to go custom like with the car :D |
@xMolchy thanks for the review. I am going to move forward with merging #221 so that you can use the updated code to assign your own custom string constraint. |
@bighappyface Sorry to hijack the already closed post, but what is the "official" way to have a functionality like @xMolchy tried to provide? Build your own constraint class and set in the factory? |
This will allow developers to create more complicated regex patterns for example #u as usage of Unicode ... only extra work in Schema is to supply pattern with starting and ending #