开发者

Symfony: question about a piece of code of sfDoctrineGuardPlugin

开发者 https://www.devze.com 2022-12-31 16:25 出处:网络
there is this code below in sfDoctrineGuardPlugin. $a = sfConfig::get(\'app_sf_guard_plugin_success_signin_url\');

there is this code below in sfDoctrineGuardPlugin.

$a = sfConfig::get('app_sf_guard_plugin_success_signin_url');

var_dump($a);

$signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $user->开发者_开发技巧getReferer($request->getReferer()));

var_dump($signinUrl);

var_dump($user->getReferer($request->getReferer()));

It prints this:

null

string 'http://rs3.localhost/frontend_dev.php/' (length=38)

string 'http://rs3.localhost/frontend_dev.php/miembros' (length=46)

I don't know why the the second and the third lines are different..any idea?

Regards

Javi


Weird. Spooky.

I wonder if maybe the two calls to getReferer() are in different contexts? Maybe the first (as the second arg to sfConfig::get()) implicitly uses __toString() whereas when you use var_dump(), maybe it's printing the raw value of the referer object?

Hrmm... the API says getReferer() returns a string, so that's probably not it.

What are you trying to do, BTW? Is it not honoring your app_sf_guard_plugin_success_signin_url setting from app.yml?


sfDoctrineGuardPlugin sets a referer attribute in the user, so that it can redirect back to the page originally requested. When you call getReferer it removes the attribute. (This is causing bugs for me, which is what brought me here.)


yitznewton pointed me towards a solution. The sfGuardSecurityUser class uses a method setReferer that saves a referer attribute but only if one is not yet set.

If somehow you manage to get to the executeSignin method in the sfGuard actions twice only the first referer attribute will be saved, this means that the second time the referer in the request and the referer in the user attribute can be different.

The getReferer method removes that attribute, and falls back to the request referer when the attribute is not set. this explains why calling $user->getReferer($request->getReferer()) twice returns different values sometimes.

The solution i found was to overwrite the setReferer method of the sfGuardSecurityUser in the myUser class:

public function setReferer($referer) {
    $this->setAttribute('referer', $referer);
}

So far i have not found any side effects, this change ensures the user attribute will allways be the most recent, however there has to be a reason to explain why the symfony folk chose to implement this as it was.

Ive tested this by switching between apps on the login screen, allowing the session to die, killing the session manually and normally using the application and so far i have not found any side effects.

0

精彩评论

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