-
Notifications
You must be signed in to change notification settings - Fork 14
Added error listeners to RequestHandlerRunner #5
base: master
Are you sure you want to change the base?
Conversation
The only issue I see with this is that you would not be able to use the same listeners here as you do with the zend-stratigility function (Throwable $error, ServerRequestInterface $requst, ResponseInterface $response) If we were to do this, we'd need to find a way to either document re-use of listeners, or provide a way to curry listeners to work properly (e.g., providing an empty request instance). |
Unfortunately yes as the request object is not available. But still offers a chance to get the issue logged somewhere, maybe together with $_REQUEST. |
Empty request would also be a possibility... YES, really like the idea. One could create a class implementing ServerRequestInterface which just pipes thru the $_SERVER, $_FILES etc variables. Without triggering any exceptions. |
The other point remains: we'd need a way of currying arguments for existing listeners. It'd likely look something like this: class ErrorHandlerListenerAdapter
{
/** @var callable */
private $listener;
/** @param ServerRequestInterface */
private $request;
public function __construct(callable $listener, ServerRequestInterface $request = null)
{
$this->listener = $listener;
$this->request = $request ?: new EmptyServerRequest();
}
public function __invoke(Throwable $e, ResponseInterface $response) : void
{
($this->listener)($e, $this->request, $response);
}
}
function adaptErrorHandlerListener(callable $listener, ServerRequestInterface $request = null) : ErrorHandlerListenerAdapter
{
return new ErrorHandlerListenerAdapter($listener, $request);
} I'm not sure if that should belong here, or in the zend-expressive package, however. |
Not at my PC right now. Yes @ $_REQUEST. But why not just call the listeners in triggerListeners with the second arguments being the new EmptyServerRequest()? Why an ...Adapter? |
By currying, we can use existing listeners, and call them using the empty request instance only in this particular context; in other contexts, they get the populated request instance. That's the sole purpose of the approach I outline above. |
Now I got it; was hard to read on mobile. Another idea is to not use an EmptyServerRequest but some kind of Raw/UnitializedServerRequest which returns $_SERVER, $_FILES etc so that just have some bare minimum Request. Not sure if this is a good idea. |
* Trigger all error listeners. | ||
*/ | ||
private function triggerListeners( | ||
\Throwable $error, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\
in Throwable is not needed as already in use statement.
@maurice2k I'd like to bring this functionality in, but need:
If you cannot provide those, close the issue, and indicate somebody else should pick it up. Thanks! |
This repository has been closed and moved to laminas/laminas-httphandlerrunner; a new issue has been opened at laminas/laminas-httphandlerrunner#2. |
This repository has been moved to laminas/laminas-httphandlerrunner. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:
|
Added error listeners to RequestHandlerRunner to be able to log errors/exceptions thrown in ::run() method.
Also made emitMarshalServerRequestException public to it can be called from the outside-