zf-fr / zfr-rest

A module for Zend Framework 2 that aims to simplify RESTful

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resource specific autoHydrate/autoValidate

bakura10 opened this issue · comments

Hi,

I've come across a case today where I'd like ZfrRest NOT TO automatically hydrate my entity. The use case is a password reset. My client only sends the "email", but in the PasswordReset entity in server side, it's linked to a user. My PasswordResetService is written in a way it's only capable to create a password reset from email (createFromEmail).

There is currently a way to do it: the user service is injected into the PasswordReset hydrator, and the hydrator populate the PasswordReset. Drawback is that the query is executed twice, because the ResetPasswordService expects an email.

The second solution is to disable autoHydrate, so that ZfrRest validates data using input filter, but pass the data "as it" to the controller. However this setting is global.

It would be nice if mapping could contain a local setting for those two settings:

  • If it is null, it uses the global settings.
  • Otherwise, it uses its value.

The question is: where should this mapping data be placed?

The @rest\Resource already has quite a bunch of data (hydrator, controller and inputFilter).

I've thought about adding a new @rest\Behaviour(autoHydrate="", autoValidate="")

What do you think? ping @danizord @Ocramius

I'd suggest @REST\Controller(name="MyApp\Controller\MyController", autoHydrate=false) and remove controller from @REST\Resource.

Problem is that it changes completely the whole metadata structure. How do you specify controller for collection now if you have a specific annotation for that?

Envoyé de mon iPhone

Le 20 févr. 2014 à 20:12, Daniel Gimenes notifications@github.com a écrit :

I'd suggest @rest\Controller(name="MyApp\Controller\MyController", autoHydrate=false)


Reply to this email directly or view it on GitHub.

Ah! I forgot that, nvm.

@bakura10 What about a protected property in controller?

I second the protected controller property...
On 20 Feb 2014 20:24, "Daniel Gimenes" notifications@github.com wrote:

@bakura10 https://github.com/bakura10 What about a protected property
in controller?


Reply to this email directly or view it on GitHubhttps://github.com//issues/125#issuecomment-35658900
.

Haa. That's a nice idea.

It would replace completely the global setting variables then?

I'm going to give it a try.

Envoyé de mon iPhone

Le 20 févr. 2014 à 20:34, Marco Pivetta notifications@github.com a écrit :

I second the protected controller property...
On 20 Feb 2014 20:24, "Daniel Gimenes" notifications@github.com wrote:

@bakura10 https://github.com/bakura10 What about a protected property
in controller?


Reply to this email directly or view it on GitHubhttps://github.com//issues/125#issuecomment-35658900
.


Reply to this email directly or view it on GitHub.