Commit 65a97117 authored by Dave Marshall's avatar Dave Marshall

Avoid mutating state

parent f31bb299
...@@ -39,13 +39,13 @@ class ViewListenerWrapper ...@@ -39,13 +39,13 @@ class ViewListenerWrapper
public function __invoke(GetResponseForControllerResultEvent $event) public function __invoke(GetResponseForControllerResultEvent $event)
{ {
$controllerResult = $event->getControllerResult(); $controllerResult = $event->getControllerResult();
$this->callback = $this->app['callback_resolver']->resolveCallback($this->callback); $callback = $this->app['callback_resolver']->resolveCallback($this->callback);
if (!$this->shouldRun($controllerResult)) { if (!$this->shouldRun($callback, $controllerResult)) {
return; return;
} }
$response = call_user_func($this->callback, $controllerResult, $event->getRequest()); $response = call_user_func($callback, $controllerResult, $event->getRequest());
if ($response instanceof Response) { if ($response instanceof Response) {
$event->setResponse($response); $event->setResponse($response);
...@@ -54,15 +54,15 @@ class ViewListenerWrapper ...@@ -54,15 +54,15 @@ class ViewListenerWrapper
} }
} }
protected function shouldRun($controllerResult) protected function shouldRun($callback, $controllerResult)
{ {
if (is_array($this->callback)) { if (is_array($callback)) {
$callbackReflection = new \ReflectionMethod($this->callback[0], $this->callback[1]); $callbackReflection = new \ReflectionMethod($callback[0], $callback[1]);
} elseif (is_object($this->callback) && !$this->callback instanceof \Closure) { } elseif (is_object($callback) && !$callback instanceof \Closure) {
$callbackReflection = new \ReflectionObject($this->callback); $callbackReflection = new \ReflectionObject($callback);
$callbackReflection = $callbackReflection->getMethod('__invoke'); $callbackReflection = $callbackReflection->getMethod('__invoke');
} else { } else {
$callbackReflection = new \ReflectionFunction($this->callback); $callbackReflection = new \ReflectionFunction($callback);
} }
if ($callbackReflection->getNumberOfParameters() > 0) { if ($callbackReflection->getNumberOfParameters() > 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment