public function testCallbackGetSet() { // Test functions $test_callable = $this->getTestCallable(); $test_class_callable = __NAMESPACE__ . '\\Mocks\\TestClass::GET'; // Callback set in constructor $route = new Route($test_callable); $this->assertSame($test_callable, $route->getCallback()); $this->assertInternalType('callable', $route->getCallback()); // Callback set in method $route = new Route($test_callable); $route->setCallback($test_class_callable); $this->assertSame($test_class_callable, $route->getCallback()); $this->assertInternalType('callable', $route->getCallback()); }
/** * Handle a route's callback * * This handles common exceptions and their output * to keep the "dispatch()" method DRY * * @param Route $route * @param RouteCollection $matched * @param array $methods_matched * @return void */ protected function handleRouteCallback(Route $route, RouteCollection $matched, array $methods_matched) { // Handle the callback $returned = call_user_func($route->getCallback(), $this->request, $this->response, $this->service, $this->app, $this, $matched, $methods_matched); if ($returned instanceof AbstractResponse) { $this->response = $returned; } else { // Otherwise, attempt to append the returned data try { $this->response->append($returned); } catch (LockedResponseException $e) { // Do nothing, since this is an automated behavior } } }
/** * Handle a route's callback * * This handles common exceptions and their output * to keep the "dispatch()" method DRY * * @param Route $route * @param RouteCollection $matched * @param int $methods_matched * @access protected * @return void */ protected function handleRouteCallback(Route $route, RouteCollection $matched, $methods_matched) { // Handle the callback try { $returned = call_user_func($route->getCallback(), $this->request, $this->response, $this->app, $this, $matched, $methods_matched); if ($returned instanceof AbstractResponse) { $this->response = $returned; } else { // Otherwise, attempt to append the returned data try { $this->response->append($returned); } catch (LockedResponseException $e) { // Do nothing, since this is an automated behavior } } } catch (DispatchHaltedException $e) { throw $e; } catch (HttpExceptionInterface $e) { // Call our http error handlers $this->httpError($e, $matched, $methods_matched); throw new DispatchHaltedException(); } catch (Exception $e) { $this->error($e); } }