本文整理汇总了PHP中Illuminate\Routing\Router::getCurrentRoute方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::getCurrentRoute方法的具体用法?PHP Router::getCurrentRoute怎么用?PHP Router::getCurrentRoute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Routing\Router
的用法示例。
在下文中一共展示了Router::getCurrentRoute方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: invoke
/**
* 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) {
}
}
示例2: pageUrl
/**
* 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);
}
示例3: getControllerAndAction
/**
* 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);
}
示例4: hasAccess
/**
* @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);
}
示例5: invoke
/**
* 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());
}
}
示例6: execute
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;
}
示例7: callFilter
/**
* 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);
}
}
示例8: previousPageUrl
/**
* 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);
}
示例9: invoke
/**
* 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());
}
}
示例10: index
/**
* 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;
}
示例11: getCurrentRoute
/**
* Get the currently dispatched route instance.
*
* @return \Illuminate\Routing\Route
* @static
*/
public static function getCurrentRoute()
{
return \Illuminate\Routing\Router::getCurrentRoute();
}
示例12: getRouteName
/**
* Return current route name
*
* @return string
*/
protected function getRouteName()
{
return $this->router->getCurrentRoute()->getName();
}
示例13: listMembers
/**
* 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'));
}
示例14: callAfterFilters
/**
* 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));
}
}