We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to get fired `beforeAuthorizationResolve` without call to `getHeaders()`

If I take an example from documentation it all works as expected. But if I remove $request->getHeaders() line event beforeAuthorizationResolve is not fired. I don't headers to if I only want to use this event.

After some check in the source code I thinks it's missing call to the this->resolveAuthorizationHeaders(); and I can't see any other way how to call this method without getting all headers to my self.

I've never used this functionality, but it seems to me that beforeAuthorizationResolve() can only be fired after getHeaders() because whether or not authorization needs to happen depends on whether or not authorization headers were sent.


But it shouldn't be like that, I mean I don't need get all headers just to check authorization header. I think it migth be a bug here or missing something in documentation.


Request:::resolveAuthorizationHeaders() is responsible for populating the header info into Phalcon's structure, and firing the beforeAuthorizationResolve event.

That method is only called by Request::getHeaders(), so yes, you do need to get all headers (you're basically just copying from one array to the other). This might be a conceptual error on the dev's part, but the performance overhead is negligable to be honest.


Ok, understood. I will use it as it is with that extra call for now and hope someone will fix it later. I think it's weird to call methods that is not nesseery at all just to get some side work done (in this case fire event). For me it even make more sence to call Request:::resolveAuthorizationHeaders() since it's doing only that what I need to do.

Thanks for help :)