开发者

Symfony user framework design problem

开发者 https://www.devze.com 2023-01-04 01:43 出处:网络
I\'m looking for advice on how to tackle a design problem I\'ve came up with. I\'m currently using Symfony framework so I\'ll be using the names of开发者_如何转开发 Symfony classes.

I'm looking for advice on how to tackle a design problem I've came up with. I'm currently using Symfony framework so I'll be using the names of开发者_如何转开发 Symfony classes.

When a user becomes "authenticated" or their "credentials" change in the Symfony user class, a regenerate() gets called on the currently used storage class. The store class extends sfStorage.

Now, when this regenerate() command is ran, we need to do some business logic. The following are options I've came up with so far:

  • Modify the three functions that addCredential, removeCredential, setAuthenticated and tell them to dispatch an event (setAuthenticated already does) so we know to do our business logic.

  • Second option would be to extend the sfSessionStorage class and tell it to throw an event on each regenerate. The problem I have with this is that sfUser asks for the interface sfStorage. Unless we modify sfStorage then if someone passed any kind of class that extends sfStorage that didn't know to add the event, it wouldn't work.

  • The third option would be the second option, but we would still extend the user object to say that we require the interface of a custom sfStorage abstract class that sends out a notification on regenerate. Then we would know for sure that any class that passes through would follow this notification method.

Anyone have any suggestions?


I would go with the second option and extend the sfSessionStorage class, and then use the class by inserting it into the factories.yml.

This shouldn't cause any issues with the sfUser though as your custom storage class will extend from sfStorage by proxy.

0

精彩评论

暂无评论...
验证码 换一张
取 消