-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] RFC: Integrate Zend\Filter into Form #3973
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
That would be a great addition to the form component. The only drawback I see when opting for ZF2 would be the huge list of dependencies on other ZF2 components. |
Also, DMS\Filter can have many more filters, just make a request for them and i'll get on that. I already have a bundle for it and would be glad to fix anything left behind. Thanks @bschussek |
I've got a few questions about filters:
|
👍 for DMS-Filters. It already makes use of Doctrine\Common (which is, in fact, a Symfony2 dependency) and I love the fact that Symfony2 uses/supports small stand-alone-one-task-at-a-time libraries (such like Monolog). |
@marijn Thanks for bringing this up. Filters would use the BIND_NORM_DATA event, i.e. they would be applied on the normalized data during binding. The normalized data would then be transformed back to the client and application format in order to reflect the changes of the filter. Filters are unidirectional. Bidirectional filters are no filters, but data transformers. What the filter does depends entirely on its implementation. StripTags for example strips tags away, StringToLower converts to lowercase characters etc. @rdohms Thanks for the feedback. I will keep it in mind. |
Not sure that Zend\Filter has so many dependencies, using a more mature and complete solution is better. ZF2 will use some SF2 features, so why can't we do the same ? :) |
I'll clarify a few points about Zend_Filter. ZF2's filters are primarily oriented at normalization -- not validation. As such, they generally transform the input and return the transformed version -- thus "StringToLower" transforms the input to lowercase. Zend\Filter\FilterChain can be of interest for chaining multiple filters, and thus creating an end result that is the product of each filter -- a filter with StringTrim followed by Alpha followed by StringToLower would transform " the WORD" to "theword". Regarding dependencies -- we plan to go through the package and identify optional dependencies as distinct from required dependencies. In most cases, the only dependencies are optional -- they're necessary if you use a particular filter, but not another. In some cases, dependencies will be disappearing; as an example, because we're rewriting the i18n/l10n layer, and the approach will be quite different, many of the locale-aware filters will either remove that dependency, be moved to a separate component, or make the dependency optional. This work should be largely complete by our upcoming beta4 release (scheduled sometime in the next 4 weeks). One additional note, Zend\Filter\Input will be removed for beta4, as it is being replaced by a new Zend\InputFilter component (which bridges Zend\Filter and Zend\Validator). |
I've been using |
@weierophinney indeed .. all we are missing is a solution for normalization/sanitization DMS filter has the advantage of using similar infrastructure than what we already use in Symfony2 (at least for annotations). Looking at simply the number of filters provided by https://github.com/rdohms/DMS-Filter/tree/master/Rules and https://github.com/zendframework/zf2/tree/master/library/Zend/Filter its clear that Zend Filter is more mature and I guess if they do refactor it to Zend\InputFilter then at least the broad set of filters will remain and I doubt that there will much instability introduced in the process. That being said, I don't think its very hard to get DMS up to speed, especially since Zend Framework is BSD licensed, we could in theory just take their filters and adapt them into DMS. |
@lsmith77 indeed. DMS\Filter was modeled after Symfony\Validation so yes it does really look similar. I did take a look at the ZF Filter list and discussed this with @weierophinney and did indeed note that we follow very different paths. I have a focus on annotations and pure unidirectional filtering, while ZF has filtering/transformation. Since Symfony already has transformation i really focused on the missing filtering step. Please feel free to open any issues with Filter requests, I will be implementing a few hooks and rules and generally updating the library in the next months. |
@weierophinney Thank you for the clarification. Do you have any plans (and a schedule) to add Composer support to the individual components? In general, I don't think that the surrounding infrastructure of the filters (annotations, filter chains etc.) is of any importance for us. We just need a set of filters that transform values into filtered values. These filters will be executed sequentially directly by the form extension. I especially don't want to mix the data model with input filtering, i.e., put filter rules into the model via annotations. Doing this violates SoC. Objectively speaking, Zend\Filter seems far more mature (multibyte support, encryption, compression) and thus is my clear favorite. If it manages to
it fulfills all our requirements. @rdohms I appreciate your offer, but I don't see the point in duplicating efforts unless it makes a big difference for us. |
@bschussek No prob. Just exaplin to me why annotation based filtering violates the SoC and not validation? To me they are 2 parts of the same coin. Having filtering on form level does not also eliminate the need for entity level filtering. |
@rdohms The validator component is about validating the object, not the form. On the other hand, the filtering described by @bschussek previously would be applied on the normData of the form, not on the appData (i.e. the object), so it is part of the form level, not of the domain object level |
@stof But that would leave out filtering of data for scenarios were no form is used with an domain object. This might be necessary and useful. |
@daFish if you have some stuff needing to be done each time you set a value in an object, the right place to put the logic is the setter. |
@stof The same argument can be applied to validation: Everytime I set a value on my object it should be validated. |
@stof what about DRY? Some filters have a lot of code, putting such code in every setter is quite a recipe for disaster. |
i have to agree with @daFish the motivation behind filtering in annotations is the same as for validation. So if validation is auto executed by forms, filtering to me is on the same level. Validation in Symfony forms is not available on the form configuration IIRC, so why would filtering be form specific and not part of the domain? |
Thus far I agree with @daFish on this. If |
We could support filtering both on domain objects and on forms directly (like with validation constraints, although this is only partially finished by now). @rdohms: What about basing DMS-Filters on Zend\Filter instead of implementing your own rules? This way we could have the best of both worlds. |
@bschussek i had this talk with @weierophinney yesterday. What is your definition of basing them on ZF? Adding ZF as a depedency? or defining the same filters? I was actually looking into ZF yesterday to separate data transformations from filtering, and most of the actual filters are already implemented in DMS, but i'always open to suggestions and improvements, i have been meaning to leverage the filter_* functions in the filters, whenever it makes sense. |
@rdohms I'm speaking about actually using their filters, i.e. anything that implements Zend\Filter\Filter, only from within your walker. |
@bschussek i have a little bit of an issue with that, as the library was meant to have a small footprint. I can however look into making a hook so it can plug ZF in maybe. Will look into the interfaces and see if that possible without creating frankenstein, |
Hi! I'm using DMS-Filter and I'm pretty happy with its content. I'd also attempt as much as I could to bring 20+ dependencies only to be able to have a filtering librabry. Cheers, |
@weierophinney is there an estimation when a first RC is planned or when we could expect a stable ZF2 release? |
Can you elaborate?
This is wrong. Please see the comparison sheet I added above. |
@bschussek Some of the filters supported by Zend don't make sense for the Form component IMHO (like (Un)Compress, (De)Encrypt f.e. because they have to be bidirectional, all filters related to files (Basename, Realpath, etc.)). |
@jalliot you are right about compression and decryption. The file filters on the other hand do well make sense for uploaded files. This way, an uploaded file could be automatically en/decrypted or (de-)compressed. I like this. Having the compression and encryption filters decoupled from the file specific ones does not hurt, so I won't strike them out above. |
I didn't thought of that... That could be indeed pretty cool if handled correctly |
@bschussek it would be nice to flag what is a filter and what is actually data transformation. Basename for example I consider to be data transformation not filtering. Same with the compress/encrypt stuff. Filtering has a different purpose of avoiding bad data to come through, not of auto-converting data into other formats. Even Boolean is on a thin line here between transformation and filtering, in my approach i just did a simple cast so that its interpreted as a boolean after filtering. If we are looking for transformation and filtering in this implementation, then DMS has no way of competing. |
@rdohms You raise a valid point. I adjusted the table accordingly. |
@bschussek nice, ok I already did PregReplace this week, have not tagged a new release yet, but i'll take a look into that list and implement a few more. To your point of using ZF in DMS, i'm going to see if its possible to implement a ZendRule, so it would be something like: @filter\Zend('Zend\Filter[name]', [params]) That way it can leverage the Zend filters if you have them locally. Have not looked if that's possible, but if its interesting to anyone i'll work on it. |
That's not quite what I meant and probably a waste of time. I was rather speaking about avoiding to duplicate all the filter implementations (and their maintenance). |
@bschussek i know, but i would rather keep a functional DMS library with reasonable support and leverage extra filters without requiring them. That way people like @guilhermeblanco can still use it in a simple format, and people who want to leverage ZF can also do it. I seriously do not want to make the library depend on ZF, so i would like to keep it optional. Even if its not "selected" for this feature, feels like i'm betraying the reason i made it in the first place. But yeah that a personal opinion. |
@bschussek My idea is pretty simple. When I started to use Zend\Filter, I remember that I had to import around 10 dependencies to get it working isolated. When I made the switch to DMS-Filter, all I had to do is add a simple EventSubscriber (I have to admit it's a very dirty code I wrote in 5min) and add a new instance on every form type. Of course that would be incredibly easier if form component includes a new event monitoring through a tag. That would simplify my life. <service id="dms.filter.listener.filter" class="DMS\FilterBundle\Listener\FilterSubscriber">
<argument type="service" id="dms.filter.service.filter" />
<tag name="form.event_listener" event="postBind" method="postBind" />
</service> By doing that, it means Subscriber would be always active, so I wouldn't need to keep instantiating it every time I have a Form Type. In the case of using the component standalone (for non-form VOs), I imply need to grab the "dms.filter" service. As people already mentioned, I used it only for input filtering, not for transformation. That can be a good reason why the tool fits so well on my specific environment. |
@guilhermeblanco forms are not managed by the DIC so using a tag would not work (the DIC cannot hook in your query builder). However, if you want to have a subscriber which is always active, you could create a form type extension applied on |
@stof I don't see how it can't be managed. |
@guilhermeblanco The issue is that you don't have one Form but many (even if your controller only use one form, there is many Form objects as each subform is a Form too). So on which one would you register the listener (each one has its own dispatcher). Tags are allowing to hook into the factory, which is a container-scoped service. I don't see how you could use tags for the forms (keep in mind they are only available at compile-time, not at runtime in the container) |
Any news about this? |
@AurelC2G as we are in beta now, we won't add any new features for 2.1 but only fix bugs. New features will be for the 2.2 release now. |
I know and I was not expecting anything sooner than 2.2, just wondering whether this subject had been completely forgotten ;) |
@AurelC2G DMS\Filter is now automatically hooking into Symfony Form using the DMSFilterBundle, so its a easy drop in for 2.1 until this is finalized. |
@AurelC2G it is not forgotten. It is delayed as the priority is the 2.1 stable release currently, not the 2.2 features |
bump |
Hey! Is there any progress on this issue? I suppose it won't be in 2.3 either? :( |
Hi there! This would be nice indeed :) |
dms/dms-filter 2.0 will come with support for embedding Zend\Filter, add to that the DMSFilterBundle and it can auto-filter entities submitted by forms as well as work as described above. Both 2.0 releases should come out next week, the filter is done the bundle just needs wrapping up to support Symfony 2.3. I'm open to feedback on anything that's missing and hope that this gives you all a good option to filtering in Symfony. |
Symfony needs input filtering to go along with validation. @rdohms it would be great for DMSFilerBundle to support all standard config formats including yml and xml. |
I added xml/yml support to DMS Filter rdohms/dms-filter#10 I plan to add support to the sf2 bundle as well. I noticed there is a lot of cross over between the validator component and this filter component such as loading xml and yml config and metadata. I think if symfony2 is going to have a filter component some re-factoring could be done to share some code between the two. |
It's been more than 2 years since this discussion was initiated. Should we definitely close it as won't fix or should we officially add it to the roadmap of the next Symfony version? |
People have voiced the need for form input filtering various times. Filtering could be added to the Form component very easily by creating an (optional) extension that enables the following API:
The big question is which library to use for filtering. Upon short research, I came upon two existing alternatives:
Does anyone know further filtering libraries? Does anyone have experience with Zend\Filter in non-ZF(2) projects?
Comparison Sheet
The text was updated successfully, but these errors were encountered: