-
Notifications
You must be signed in to change notification settings - Fork 356
Plugin-System for Validation of formats? #266
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
@steffkes Since If you ask me, I think this big switch in |
@mirfilip probably should have been clearer in my initial description - that is exactly what i did, hence the sample it's kinda okay, but especially for existing formats you are going to overwrite you have to ensure that they pass the initial implementation since it's still executed - at least in my case when calling given that phone number validation is not necessarily a crazy custom task for each project .. i think it's a bit cumbersome when you have to come up with something like this, isn't it? basically it's a hash, mapping various formats to their validation function - could be more flexible than what we have right now. but that's quick a thought i had when i was implementing my own constraints - having doubts that i'm the only one ... so it's more a proposal / question about a proposal, to come up with something a bit more flexible for (additional) formats. |
@steffkes I double read your initial post now. Correct me if I'm wrong, your proposal is the same thing I described in my second paragraph - you create your own Just to clarify what we stand on now. Looking at FormatConstraint it's obvious some formats are very naive. Filtering emails, uris, hostnames are no as easy as using I think I could play around with format validation - we need it for draft4 compliance anyway. @bighappyface @jojo1981 thoughts? |
I think the best compromise to achieve more flexible customization, as well as an overall design improvement, is to refactor That being said, I am not sure that I see an issue. The facility to define custom constraints is available but from what I am reading it looks like there is even more customization desired, which IMO is beyond the scope of this package as @mirfilip described. This JSON schema package can't do/validate everything and we can't make code changes every time a consumer wants something very custom (no offense @steffkes). |
@mirfilip i should have read your message once again before replying, you're spot on. pretty sure i've missed your second paragraph, my bad. @bighappyface i should definitely try to right better issue descriptions - having an additional dependency for a part of the library that is probably not used that often is obviously a bad choice. making it optional only would leave as with runtime checks, which isn't the best design either. no offense taken David, i was able to implement whatever crazy requirement we had - no reason to complain. the idea was more to propose an idea for further development. if we could refactor the
creditcard numbers, uuid's, vat numbers, proper base64 strings .. are just a bunch of things that come to mind. and i absolutely don't expect one library (neither this one nor an other one) to solve all of them in one shot. to say it again - it's not about what i just did to get it working. it's more about a generic/general idea on how to make this library more flexible in terms of validating various formats. right now, i think it's a bit more complicated than what's needed. i hope that clarified a few things - otherwise just say so :) |
That's sums up the longish discussion. Please have a look at ajv json-schema validator. That's exactly the @steffkes idea and the public interface is pretty much nailed. Let me know if you like the idea, I will tackle the problem during the weekend. btw. @bighappyface what do you think about adding "feature request" label? |
@mirfilip label created. I am all in favor of a more extensible system for custom constraints or implementations. |
@mirfilip just curious, did you already take a stab? i'd like to help out if & where i can. i've already added two additional format constraints (language- & country-codes based on ISO-Codes) and the list keeps growing .. ;> |
the idea of (quoting from @bighappyface)
is certainly a good one. but it's often seen with those things, that quite some performance gets lost in 'discovery' of the classes that want to validate and what they want to validate. Typically, somewhere all the So, if the simple Needless to say, that's nice - but it's slower by factors (even if currently low ones) then the current simple approach. Maybe keep the current stuff as-is, but allow to just register new My point is to keep the current "core" validation as fast as possible.. @mirfilip @steffkes |
While i absolute agree on that - it's sometimes just not feasible. and there is still the possibility to add some kind of
for me, that's just another way to phrase it. i do not really care (or rather need) to make everything super flexible - my pain came from an existing
well, if we're going to argue about something like that .. i'm not sure we're going places. if that would really be the reason why we're not doing it, then we should have a serious conversation. TL;DR: i'd be okay if we decide to remove those formats (namely |
i totally agree with ur statements.. i'd also like to have more flexibility and I'm currently struggling with stuff in
Again +1 - I was just voting for an approach that doesn't loose performance out of sight. This library mostly ends up in complex apps and is expected to be snappy - I hope that doesn't change ;-) Maybe do something using |
so then, what about the following - at least as short term goal: we refactor the rather large switch/case statement. we do so by moving for the long run, we can still refactor the really large statement - which doesn't seem needed to me anymore once we've done the refactoring just described above. |
just a quick hack over at #280, to get it out of my head. pretty sure it does not work for the given set of requirements (php 5.3 and what not) but it should be possible to get the idea @narcoticfresh |
@steffkes in an attempt to cleanup this repo we are trying to filter the issues and see which ones might be closed. Is it safe to assume this is a rather old feature request, which sadly was left unanswered, and can be closed? Feel free to close it yourself with some comments if helpful. |
@DannyvdSluijs absolutely. I'm not even doing PHP anymore .. time is flying! |
i'm using this library again for one of my projects, never had to extend it in any way since the included features were always enough - until this time ;>
there is already a part of
FormatConstraint
that validatesformat=phone
but it only does a very, very simple check on US phone numbers. i did need to perform a check on a larger range including internal numbers.libphonenumber-for-php
is a perfect fit for it, integrating that intojson-schema
and extending theFormatConstraint
feels a bit ugly.just for reference, one could or would probably:
since we extend
FormatConstraint
we'd have to givevalidatePhone
a pass since it will be called from the originalFormatConstraint#check
method which is executed anyway since we have to ensure that all the other/existing format constraints still work.the other thing is, since i'd like to include additional information in the response i need access to the exception - not a thing that all the existing
validate*
methods do right now. obviously a personal choice, but nevertheless.before i start digging in such a plugin-system, i'm curious WDYT? is it even worth it? am i the only one that needed something like this? is it probably the only extension one could ever want?
let me know!
The text was updated successfully, but these errors were encountered: