Phabric icon indicating copy to clipboard operation
Phabric copied to clipboard

Add default data transformations

Open benwaine opened this issue 14 years ago • 5 comments

Useful data translations like UP DOWN, UKTOMYSQLDATE

benwaine avatar Aug 16 '11 13:08 benwaine

I think it's more important to have a portable extension model for registering data transformers. That way it is easy to share common transformations between projects. Perhaps it could be sensical to utilize the interfaces from Symfony\Component\Form\Extension\Core\DataTransformer.

marijn avatar Aug 18 '11 16:08 marijn

As long as the interface stays consistent - ($name, $function), Then packaging up transformations separately from the application is as easy as a file/function which calls addDataTransformation a bunch of times on a passed Phabric instance.

Using anonymous functions and not having any dependencies is a great boon in my book - there's no reason this same lib couldn't be used with PHPUnit to create data on demand as well.

glenjamin avatar Aug 18 '11 21:08 glenjamin

I'm not saying that it should be using the interface from Symfony. Though I do think that having the data transformations not as anonymous functions but a more reusable element, like a class, could benefit in reusing code across projects.

Suggesting the Symfony code was more about not reinventing the wheel, but since those classes have become rather proprietary it is perhaps not the best move.

marijn avatar Aug 18 '11 21:08 marijn

Ah, I see - that makes sense.

However, I suspect the anonymous function vs class thing is more a matter of taste - I personally far prefer the functions, and find them to be perfectly re-usable if you choose to do so. There's no reason you couldn't chose the transformation name strings as something namespace-like "glenjamin.myprefereddateformat" etc.

glenjamin avatar Aug 18 '11 22:08 glenjamin

hmm, can we have a snippet here shown how it can be done with symfony2's Symfony\Component\Form\Extension\Core\DataTransformer, I am very interested please post some example, thanks!

cordoval avatar Sep 09 '11 05:09 cordoval