/** * @param RouteInfo $routeInfo * @param Request $request * @return mixed|null */ private function handleUsingClosure(Request $request, RouteInfo $routeInfo) { $response = null; $routeName = $routeInfo->getRouteName(); $closureStorage = ClosureStorage::getInstance(); if (isset($closureStorage[$routeName]) && is_callable($closureStorage[$routeName])) { $this->triggerPreActionEvent($routeInfo); $response = call_user_func_array($closureStorage[$routeName], array($request, $routeInfo)); $this->triggerPostActionEvent($routeInfo); } return $response; }
/** * @param $path * @param callable $function */ public static function post($path, \Closure $function) { $closureStorage = ClosureStorage::getInstance(); $routeName = self::getRouteNameFromPath($path, 'POST'); $closureStorage[$routeName] = $function; $collection = $collection = static::getRoutes(); $route = new Route($path, array(RouteInfo::CLOSURE => true)); $route->setMethods('POST'); $collection->add($routeName, $route); }