getCurrentRoute() public method

Get the currently dispatched route instance.
public getCurrentRoute ( ) : Illuminate\Routing\Route
return Illuminate\Routing\Route
Example #1
0
 /**
  * Call internal URI with parameters.
  *
  * @param  string $uri
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function invoke($uri, $method, $parameters = array())
 {
     // Request URI.
     $uri = '/' . ltrim($uri, '/');
     // Parameters for GET, POST
     $parameters = $parameters ? current($parameters) : array();
     try {
         // store the original request data and route
         $originalInput = $this->request->input();
         $originalRoute = $this->router->getCurrentRoute();
         // create a new request to the API resource
         $request = $this->request->create($uri, strtoupper($method), $parameters);
         // replace the request input...
         $this->request->replace($request->input());
         $dispatch = $this->router->dispatch($request);
         if (method_exists($dispatch, 'getOriginalContent')) {
             $response = $dispatch->getOriginalContent();
         } else {
             $response = $dispatch->getContent();
         }
         // Decode json content.
         if ($dispatch->headers->get('content-type') == 'application/json') {
             if (function_exists('json_decode') and is_string($response)) {
                 $response = json_decode($response, true);
             }
         }
         // replace the request input and route back to the original state
         $this->request->replace($originalInput);
         $this->router->setCurrentRoute($originalRoute);
         return $response;
     } catch (NotFoundHttpException $e) {
     }
 }
 /**
  * Generate a page URL, based on the request's current URL.
  *
  * @param int  $page
  * @param bool $full Return the full version of the URL in for the first page
  *                   Ex. /users/page/1 instead of /users
  *
  * @return string
  */
 public function pageUrl($page, $full = false)
 {
     $currentPageUrl = $this->router->getCurrentRoute()->getUri();
     $url = $this->addPageQuery(str_replace('{pageQuery?}', '', $currentPageUrl), $page, $full);
     foreach ($this->router->getCurrentRoute()->bindParameters(app('request')) as $parameterName => $parameterValue) {
         $url = str_replace(['{' . $parameterName . '}', '{' . $parameterName . '?}'], $parameterValue, $url);
     }
     return $this->urlGenerator->to($url);
 }
 /**
  * Get controller and action from current route
  *
  * @return array
  */
 protected function getControllerAndAction()
 {
     $name = $this->router->getCurrentRoute()->getActionName();
     // don't allow closures for routes protected by this middleware
     if (!str_contains($name, '@')) {
         throw new \LogicException('Closures for routes not allowed in this application');
     }
     return explode('@', $name);
 }
Example #4
0
File: Acl.php Project: morilog/acl
 /**
  * @param null $routeName
  * @return bool
  */
 public function hasAccess($routeName = null)
 {
     if ($routeName === null) {
         $routeName = $this->router->getCurrentRoute()->getName();
         if ($routeName === null) {
             return true;
         }
     }
     return $this->hasPermissionName($routeName);
 }
Example #5
0
 /**
  * Call internal URI with parameters.
  *
  * @param  string $uri
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function invoke($uri, $method, $parameters = array())
 {
     // Request URI.
     $uri = '/' . ltrim($uri, '/');
     try {
         // Store the original request data and route.
         $originalInput = $this->request->input();
         $originalRoute = $this->router->getCurrentRoute();
         // Masking route to allow testing with PHPUnit.
         // if ( ! $originalRoute instanceof Route)
         // {
         //     $originalRoute = new Route(new \Symfony\Component\HttpFoundation\Request());
         // }
         $requestMethod = strtoupper($method);
         // Create a new request to the API resource
         $request = $this->request->create($uri, $requestMethod, $parameters);
         // Replace request method and input.
         $this->request->setMethod($requestMethod);
         $this->request->replace($request->input());
         // Dispatch request.
         $dispatch = $this->router->dispatch($request);
         if (method_exists($dispatch, 'getOriginalContent')) {
             $response = $dispatch->getOriginalContent();
         } else {
             $response = $dispatch->getContent();
         }
         // Decode json content.
         if ($dispatch->headers->get('content-type') == 'application/json') {
             if (function_exists('json_decode') and is_string($response)) {
                 $response = json_decode($response, true);
             }
         }
         // Restore the request input and route back to the original state.
         $this->request->replace($originalInput);
         return $response;
     } catch (NotFoundHttpException $e) {
         throw new HmvcNotFoundHttpException('Request Not Found.');
     } catch (FatalErrorException $e) {
         throw new HmvcFatalErrorException($e->getMessage());
     }
 }
Example #6
0
 public function execute(array $args = null)
 {
     $self = $this;
     $this->layout->setEnvironment($this->viewFactory);
     if (null === $args) {
         $args = $this->router->getCurrentRoute()->parametersWithoutNulls();
     }
     foreach ($this->structure as $block => $callback_list) {
         $blocks = array();
         foreach ($callback_list as $callback) {
             $response = $this->handleResponse($this->callCallback($callback, $args));
             if (true === $response instanceof Response) {
                 return $response;
             }
             $blocks[] = $response;
         }
         $this->layout->with($block, join("\n", $blocks));
     }
     $this->layout->with($this->data);
     return $this->layout;
 }
Example #7
0
 /**
  * Call a given filter with the parameters.
  *
  * @param  string  $name
  * @param  \Symfony\Component\HttpFoundation\Request  $request
  * @param  array   $params
  * @return mixed
  */
 public function callFilter($name, Request $request, array $params = array())
 {
     if (!$this->router->filtersEnabled()) {
         return;
     }
     $merge = array($this->router->getCurrentRoute(), $request);
     $params = array_merge($merge, $params);
     // Next we will parse the filter name to extract out any parameters and adding
     // any parameters specified in a filter name to the end of the lists of our
     // parameters, since the ones at the beginning are typically very static.
     list($name, $params) = $this->parseFilter($name, $params);
     if (!is_null($callable = $this->router->getFilter($name))) {
         return call_user_func_array($callable, $params);
     }
 }
 /**
  * Get the previous page url
  * 
  * @param  bool $full  Return the full version of the url in for the first page
  *                     Ex. /users/page/1 instead of /users
  * @return string|null
  */
 public function previousPageUrl($full = false)
 {
     $previousPage = $this->previousPage();
     if ($previousPage === null) {
         return null;
     }
     // This should call the current action with a different parameter
     // Afaik there's no cleaner way to do this
     $currentPageUrl = new String($this->router->getCurrentRoute()->getUri());
     if ($previousPage === 1 && !$full) {
         $previousPageUrl = $currentPageUrl->replaceLast($this->pageName . '/{page}', '');
     } else {
         $previousPageUrl = $currentPageUrl->replaceLast('{page}', $previousPage);
     }
     return $this->urlGenerator->to($previousPageUrl);
 }
Example #9
0
 /**
  * Call internal URI with parameters.
  *
  * @param  string $uri
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function invoke($uri, $method, $parameters = array())
 {
     // Request URI.
     if (!preg_match('/^http(s)?:/', $uri)) {
         $uri = '/' . ltrim($uri, '/');
     }
     try {
         // Store the original request data and route.
         $originalInput = $this->request->input();
         $originalRoute = $this->router->getCurrentRoute();
         // Masking route to allow testing with PHPUnit.
         /*if ( ! $originalRoute instanceof Route)
           {
               $originalRoute = new Route(new \Symfony\Component\HttpFoundation\Request());
           }*/
         // Create a new request to the API resource
         $request = $this->request->create($uri, strtoupper($method), $parameters);
         // Replace the request input...
         $this->request->replace($request->input());
         // Dispatch request.
         $dispatch = $this->router->dispatch($request);
         if (method_exists($dispatch, 'getOriginalContent')) {
             $response = $dispatch->getOriginalContent();
         } else {
             $response = $dispatch->getContent();
         }
         // Decode json content.
         if ($dispatch->headers->get('content-type') == 'application/json') {
             if (function_exists('json_decode') and is_string($response)) {
                 $response = json_decode($response, true);
             }
         }
         // Restore the request input and route back to the original state.
         $this->request->replace($originalInput);
         // This method have been removed from Laravel.
         //$this->router->setCurrentRoute($originalRoute);
         return $response;
     } catch (NotFoundHttpException $e) {
         //trigger_error('Not found');
         var_dump($e->getMessage());
     } catch (FatalErrorException $e) {
         var_dump($e->getMessage());
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request, Router $router)
 {
     /** @var Model $listClass */
     $listClass = app($this->getListClassName());
     $builder = $listClass->newQuery();
     foreach ($request->get('sorting', []) as $field => $direction) {
         $builder->orderBy($field, $direction);
     }
     // foreach
     /** @var Paginator $pagination */
     $pagination = $builder->where($request->get('filter', []))->paginate((int) $request->get('limit', 30))->appends($request->query());
     $count = count($pagination);
     $return = [];
     if ($total = $pagination->total()) {
         $baseURI = $router->getCurrentRoute()->getUri();
         $rows = [];
         $links = ['self' => ['href' => $pagination->url($pagination->currentPage())]];
         if ($total > $count) {
             $links['first'] = ['href' => $pagination->url(1)];
             $links['last'] = ['href' => $pagination->url($pagination->lastPage())];
             if ($pagination->hasMorePages()) {
                 $links['next'] = ['href' => $pagination->nextPageUrl()];
             }
             if ($pagination->currentPage() > 1) {
                 $links['prev'] = ['href' => $pagination->previousPageUrl()];
             }
             // if
         }
         /** @var Model $row */
         foreach ($pagination as $index => $row) {
             $rows[$index] = array_merge(['_links' => ['self' => ['href' => url($baseURI, $row->id)]]], $row->toArray());
         }
         $return = ['_embedded' => [$listClass->getTable() => $rows], '_links' => $links, 'count' => $count, 'take' => $pagination->perPage(), 'total' => $total];
     } else {
         if (!$count) {
             abort(404);
         }
     }
     // elseif
     // TODO 205, links in list.
     return $return;
 }
Example #11
0
 /**
  * Get the currently dispatched route instance.
  *
  * @return \Illuminate\Routing\Route 
  * @static 
  */
 public static function getCurrentRoute()
 {
     return \Illuminate\Routing\Router::getCurrentRoute();
 }
 /**
  * Return current route name
  *
  * @return string
  */
 protected function getRouteName()
 {
     return $this->router->getCurrentRoute()->getName();
 }
 /**
  * Return data for all members within the system
  *
  * @return array
  */
 public function listMembers(Router $router)
 {
     $uri = $router->getCurrentRoute()->uri();
     $users = User::whereRaw('id != 1')->orderBy('created_at')->get();
     foreach ($users as $key => $user) {
         foreach ($user->standings as $standing) {
             if (empty($standing->end_date)) {
                 $user->activeStanding = $standing->type;
             }
         }
     }
     return view('members.list', compact('uri', 'users'));
 }
Example #14
0
 /**
  * Call the after filters on the controller.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @param  string  $method
  * @param  \Symfony\Component\HttpFoundation\Response  $response
  * @return mixed
  */
 protected function callAfterFilters($router, $method, $response)
 {
     $route = $router->getCurrentRoute();
     // When running the before filters we will simply spin through the list of the
     // filters and call each one on the current route objects, which will place
     // the proper parameters on the filter call, including the requests data.
     $request = $router->getRequest();
     $filters = $this->getAfterFilters($request, $method);
     foreach ($filters as $filter) {
         $this->callFilter($route, $filter, $request, array($response));
     }
 }