/** * Implements convenient method of calling static methods from * controller's model. * * @return mixed */ public function __call($method, $args) { if (preg_match('/^staticModel([a-zA-Z0-9]+)$/', $method, $m)) { $modelClass = $this->getModelClass(); $modelMethod = lcfirst($m[1]); return call_user_func_array(array($modelClass, $modelMethod), $args); } return parent::__call($method, $args); }
/** * Register the spamguard middleware on a controller. * * @param Controller $controller * @param array $actions * @param array $elements * @return void */ public function assign(Controller $controller, $actions = [], $elements = []) { $elements = $elements ?: Config::$elements; foreach ($elements as $middleware) { $controller->middleware($middleware, $actions); } }
/** * Inject the controller dependencies into the controller instance. * * @param \Illuminate\Routing\Controller $instance * * @return void */ protected function injectControllerDependencies($instance) { try { $instance->setDispatcher($this->container['api.dispatcher']); $instance->setAuthenticator($this->container['api.auth']); $instance->setResponseFactory($this->container['api.response']); } catch (BadMethodCallException $exception) { // This controller does not utilize the trait. } }
/** * Execute an action on the controller. * * And is fired pre and post events on controller * * @param string $method * @param array $parameters * @return \Symfony\Component\HttpFoundation\Response */ public function callAction($method, $parameters) { $this->beforeCallAction($method); $this->response = parent::callAction($method, $parameters); $this->afterCallAction($method); return $this->response; }
/** * Calls controller action. * * @param string $method * @param array $parameters * @return mixed */ public function callAction($method, array $parameters = []) { $isAjax = app()->make('request')->ajax(); $method = $this->checkAjaxMethod($method, $isAjax); $parameters = $this->checkParametersResolving($method, $parameters); return parent::callAction($method, $parameters); }
/** * @param string $method * @param array $routingParameters * @return \Illuminate\View\View|mixed */ public function callAction($method, $routingParameters) { $objects = []; $this->setupLayout(); try { $methodParams = $this->detectParameters($method); } catch (ReflectionException $ex) { return parent::callAction($method, $routingParameters); } foreach ($routingParameters as $rpKey => $rpValue) { if (is_object($rpValue)) { $objects[get_class($rpValue)] = $rpValue; unset($routingParameters[$rpKey]); } } $parameters = array_merge($this->matchClasses($methodParams, $objects), $routingParameters); $response = call_user_func_array(array($this, $method), $parameters); // If no response is returned from the controller action and a layout is being // used we will assume we want to just return the layout view as any nested // views were probably bound on this view during this controller actions. if (is_null($response) && !is_null($this->layout)) { $response = $this->layout; } return $response; }
/** * Make a controller instance via the IoC container. * * @param string $controller * @return mixed */ protected function makeController($controller) { if ($this->creator) { Controller::setRouter($this->router); return $this->creator->createController($controller, $this->getPage()); } return parent::makeController($controller); }
public function __call($method, $parameters) { if (starts_with($method, 'respond')) { $responseBuilder = new ResponseBuilder($this->format, ['only' => $this->only, 'modelName' => $this->getModelName(), 'includes' => $this->request->has('includes') ? $this->request->get('includes') : []]); return call_user_func_array([$responseBuilder, $method], $parameters); } return parent::__call($method, $parameters); }
/** * Execute an action on the controller. * * @param string $method * @param array $parameters * @return \Symfony\Component\HttpFoundation\Response */ public function callAction($method, $parameters) { $result = parent::callAction($method, $parameters); if (app('ajax.helper')->isFrameworkAjax()) { $result = $this->prepareAjaxActionResponse($result); } return $result; }
public function edit($entity) { parent::edit($entity); $this->edit = \DataEdit::source(new \User()); $this->edit->label('Edit User'); $this->edit->link("rapyd-demo/filter", "Articles", "TR")->back(); $this->edit->add('name', 'Name', 'text')->rule('required|min:5'); $this->edit->add('username', 'userame', 'text')->rule('required|min:5'); return $this->returnEditView(); }
/** * Get the middleware for the controller instance. * * @param \Illuminate\Routing\Controller $instance * @param string $method * @return array */ protected function getMiddleware($instance, $method) { $results = new Collection(); foreach ($instance->getMiddleware() as $name => $options) { if (!$this->methodExcludedByOptions($method, $options)) { $results[] = $this->router->resolveMiddlewareClassName($name); } } return $results->flatten()->all(); }
/** * Get an instance of the possible current controller * being executed for the current route. * * @return mixed */ protected function getCurrentController() { $router = $this->app->make('router'); $route = $router->currentRouteAction(); if (($pos = strpos($route, '@')) !== false) { Controller::setFilterer($router); $controllerName = substr($route, 0, $pos); return $this->app[$controllerName]; } }
public function validateRequest($request, $rules) { $validator = $this->getValidationFactory()->make($request->all(), $rules); if ($validator->fails()) { $message = array(); foreach ($validator->errors()->getMessages() as $field => $errorMsg) { $message[] = $errorMsg[0]; } $message = implode('|', $message); throw new HttpResponseException(Response::json(ResponseManager::error($message))); } return parent::validateRequest($request, $rules); }
/** * @param string $method * @param array $parameters * @return \Illuminate\Contracts\View\View */ public function callAction($method, $parameters) { $altResponseContent = parent::callAction($method, $parameters); if (is_null($altResponseContent)) { $this->layoutData = array_merge(['system_menu' => AdminMenu::getSystemMenu(), 'sections_menu' => Auth::admin() ? AdminMenu::getSectionsMenu() : '', 'coaster_routes' => Routes::jsonRoutes()], $this->layoutData); } event(new LoadResponse($this->layout, $this->layoutData, $altResponseContent, $this->responseCode)); if (is_a($altResponseContent, \Symfony\Component\HttpFoundation\Response::class)) { return $altResponseContent; } else { $responseContent = is_null($altResponseContent) ? View::make($this->layout, $this->layoutData) : $altResponseContent; } return Response::make($responseContent, $this->responseCode); }
/** * Return the content. * * @param string $method * @param array $parameters * * @return mixed */ public function callAction($method, $parameters) { /* * First, we need to get the actual response contents through the * parent function. */ $response = parent::callAction($method, $parameters); /* * Secondly we need to instantiate all classes so we don't have * to do this over and over again during various calls. */ $this->setClasses(); /* * Then we set the formatter to the one that matches the content * type the user wants to have the data returned in. */ $this->setFormatter(); /* * And finally we return the response. */ return $this->formatter->response($response, $this->statusCode); }
/** * Get the middleware for the controller instance. * * @param \Illuminate\Routing\Controller $instance * @param string $method * @return array */ protected function getMiddleware($instance, $method) { $middleware = $this->router->getMiddleware(); $results = []; foreach ($instance->getMiddleware() as $name => $options) { if (!$this->methodExcludedByOptions($method, $options)) { $results[] = array_get($middleware, $name, $name); } } return $results; }
/** * Make a controller instance via the IoC container. * * @param string $controller * @return mixed */ protected function makeController($controller) { Controller::setRouter($this->router); return $this->container->make($controller); }
/** @inheritdoc */ public function pushRouteMiddleware(Controller $controller) { foreach ($this->routeMiddleware as $_middleware) { $controller->middleware($_middleware); } return $this; }
/** * Make a controller instance via the IoC container. * * @param string $controller * @return mixed */ protected function makeController($controller) { Controller::setFilterer($this->filterer); return $this->container->make($controller)->setContainer($this->container); }
/** * Apply the applicable after filters to the route. * * @param \Illuminate\Routing\Controller $instance * @param \Illuminate\Routing\Route $route * @param \Illuminate\Http\Request $request * @param string $method * @return mixed */ protected function assignAfter($instance, $route, $request, $method) { foreach ($instance->getAfterFilters() as $filter) { // If the filter applies, we will add it to the route, since it has already been // registered on the filterer by the controller, and will just let the normal // router take care of calling these filters so we do not duplicate logics. if ($this->filterApplies($filter, $request, $method)) { $route->after($this->getAssignableAfter($filter)); } } }
/** * Get the middlewares for the given controller instance and method. * * @param \Illuminate\Routing\Controller $controller * @param string $method * @return array */ protected function getControllerMiddlewareFromInstance($controller, $method) { $middleware = $this->router->getMiddleware(); $results = []; foreach ($controller->getMiddleware() as $name => $options) { if (!$this->methodExcludedByOptions($method, $options)) { $results[] = Arr::get($middleware, $name, $name); } } return $results; }
/** * Revise the protected state of a controller method. * * @param \Dingo\Api\Routing\Route $action * @param \Illuminate\Routing\Controller $controller * @param string $method * * @return void */ protected function reviseProtection(Route $route, $controller, $method) { $properties = $controller->getProperties(); if (isset($properties['*']['protected'])) { $route->setProtected($properties['*']['protected']); } if (isset($properties[$method]['protected'])) { $route->setProtected($properties[$method]['protected']); } }
/** * Magically handle calls to the response builder. * * @param string $method * @param array $parameters * @return mixed */ public function __call($method, $parameters) { if (method_exists($this->response, $method)) { return call_user_func_array([$this->response, $method], $parameters); } return parent::__call($method, $parameters); }
public function __construct() { parent::__construct(); }
/** * Execute an action on the controller. * * @param string $method * @param array $parameters * * @return array */ public function callAction($method, $parameters) { $this->responseArray['type'] = Response::TYPE_CONTENT; $this->responseArray['method'] = Request::method(); $this->responseArray['code'] = Response::NO_ERROR; if (isset($this->requiredFields[$method]) and is_array($this->requiredFields[$method])) { $this->validateParameters($this->requiredFields[$method]); } $response = parent::callAction($method, $parameters); if ($response instanceof RedirectResponse) { $this->responseArray['type'] = Response::TYPE_REDIRECT; $this->responseArray['targetUrl'] = $response->getTargetUrl(); $this->responseArray['code'] = $response->getStatusCode(); } else { if ($response instanceof View) { return new JsonResponse($response->render()); } else { if ($response instanceof JsonResponse) { return $response; } } } return (new Response(config('app.debug')))->createResponse($this->responseArray); }
/** * Execute an action on the controller. * * @param string $method * @param array $parameters * @return \Illuminate\Http\Response */ public function callAction($method, $parameters) { $rMethod = new ReflectionMethod($this, $method); $resolver = new MethodArgumentResolver($this->container); return Controller::callAction($method, $resolver->resolve($rMethod, $parameters)); }
/** * Execute an action on the controller. * * @param string $method * @param array $parameters * * @return \Symfony\Component\HttpFoundation\Response */ public function callAction($method, $parameters) { $response = $parentResponse = null; try { $response = $parentResponse = parent::callAction($method, $parameters); } catch (\Exception $e) { $notFoundExceptions = array('Illuminate\\Database\\Eloquent\\ModelNotFoundException', 'Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException'); $errorExceptions = array('Subbly\\Api\\Service\\Exception'); if (in_array(get_class($e), $notFoundExceptions)) { return $this->jsonNotFoundResponse($e->getMessage()); } elseif (in_array(get_class($e), $errorExceptions)) { return $this->jsonErrorResponse($e->getMessage()); } elseif ($e instanceof \Subbly\Model\Exception\UnvalidModelException) { return $this->jsonErrorResponse($e->firstErrorMessage()); } $response = $this->jsonErrorResponse('Fatal error!'); } if (App::environment('local', 'testing')) { return $parentResponse ?: parent::callAction($method, $parameters); } return $response; }