本文整理汇总了PHP中Illuminate\Routing\Route::getAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::getAction方法的具体用法?PHP Route::getAction怎么用?PHP Route::getAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Routing\Route
的用法示例。
在下文中一共展示了Route::getAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(Route $route = null)
{
if (!$route || !array_key_exists('controller', $route->getAction())) {
return;
}
// route will be null when not called by documentor
list($controller, $method) = explode('@', $route->getAction()['controller']);
$this->handler = explode('\\', $route->getAction()['controller']);
$this->handler = end($this->handler);
$this->hash = md5($this->handler);
$this->group = $this->getApiGroup($controller, $method);
$this->groupHash = md5($this->group);
$this->sort = $this->getApiSort($controller, $method);
$this->path = $route->uri();
$this->httpMethod = $route->getMethods()[0];
$this->controllerMethod = $method;
$this->controller = $controller;
$this->title = $this->getApiTitle($controller, $method);
$this->description = $this->getApiDescription($controller, $method);
$requestclass = $this->getRequestClass($controller, $method, $this->path, $this->httpMethod);
$this->inputProps = $requestclass ? $requestclass->apiFields() : [];
$this->response = $requestclass ? $requestclass->exampleResponse() : '';
$this->urlIdMap = $this->getUrlIdMap($controller);
$this->responseCodes = $this->getResponseCodes($controller, $method, !!$this->inputProps);
}
示例2: getRouteInformation
/**
* Get the route information for a given route.
*
* @param $route \Illuminate\Routing\Route
* @param $filter string
* @param $namespace string
*
* @return array
*/
protected function getRouteInformation(Route $route, $filter, $namespace)
{
$host = $route->domain();
$methods = $route->getMethods();
$uri = $route->uri();
$name = $route->getName();
$action = $route->getActionName();
$jsroute = array_get($route->getAction(), 'jsroute', null);
if (!empty($namespace)) {
$a = $route->getAction();
if (isset($a['controller'])) {
$action = str_replace($namespace . '\\', '', $action);
}
}
switch ($filter) {
case 'all':
if ($jsroute === false) {
return null;
}
break;
case 'only':
if ($jsroute !== true) {
return null;
}
break;
}
return compact('host', 'methods', 'uri', 'name', 'action');
}
示例3: resolve
/**
* Resolve the page.
*
* @return Contract\PageInterface|null
*/
public function resolve()
{
$action = $this->route->getAction();
if ($id = array_get($action, 'anomaly.module.pages::page')) {
return $this->pages->find($id);
}
if ($path = array_get($action, 'anomaly.module.pages::path')) {
return $this->pages->findByPath($path);
}
return null;
}
示例4: redirect
/**
* Redirect elsewhere.
*
* @param PageRepositoryInterface $pages
* @param Redirector $redirector
* @param Route $route
* @return \Illuminate\Http\RedirectResponse|void
*/
public function redirect(PageRepositoryInterface $pages, Redirector $redirector, Route $route)
{
if ($to = array_get($route->getAction(), 'anomaly.module.pages::redirect')) {
return $redirector->to($to, array_get($route->getAction(), 'status', 302));
}
/* @var PageInterface $page */
if ($page = $pages->find(array_get($route->getAction(), 'anomaly.module.pages::page', 0))) {
return $redirector->to($page->getPath(), array_get($route->getAction(), 'status', 302));
}
abort(404);
}
示例5: getControllerName
function getControllerName()
{
$route = new Route();
print $route->getActionName();
print "<br />";
print $route->getAction();
}
示例6: getActionReflection
/**
* @return \ReflectionFunctionAbstract|null
*/
protected function getActionReflection()
{
if ($this->actionReflection) {
return $this->actionReflection;
}
$uses = $this->route->getAction()['uses'];
// Если это строка и она содержит @, значит мы имем дело с методом контроллера.
if (is_string($uses) && str_contains($uses, '@')) {
list($controller, $action) = explode('@', $uses);
// Если нет контроллера.
if (!class_exists($controller)) {
$this->setError('uses', 'controller does not exists');
return null;
}
// Если нет метода в контроллере.
if (!method_exists($controller, $action)) {
$this->setError('uses', 'controller@method does not exists');
return null;
}
return $this->actionReflection = new \ReflectionMethod($controller, $action);
}
if (is_callable($uses)) {
return $this->actionReflection = new \ReflectionFunction($uses);
}
$this->setError('uses', 'route uses is not valid');
return null;
}
示例7: getRouteInformation
/**
* Get the route information for a given route.
*
* @param string $name
* @param Route $route
* @param Route $current the current route
* @param string $base_path
* @return array
*/
protected function getRouteInformation($name, Route $route, $current, $base_path)
{
$path = $route->getPath();
$uri = head($route->getMethods()) . ' <a href="' . $base_path . $path . '">' . $path . '</a>';
$action = $route->getAction() ?: 'Closure';
return array('current' => $current == $route, 'host' => $route->getHost(), 'uri' => $uri, 'name' => $this->getRouteName($name), 'action' => $action, 'before' => $this->getBeforeFilters($route), 'after' => $this->getAfterFilters($route));
}
示例8: addLookups
/**
* Add the route to any look-up tables if necessary.
*
* @param Route $route illuminate route
*
* @return void
*/
protected function addLookups($route)
{
// If the route has a name, we will add it to the name look-up table so that we
// will quickly be able to find any route associate with a name and not have
// to iterate through every route every time we need to perform a look-up.
$action = $route->getAction();
if (isset($action['as'])) {
if (isset($action['module'])) {
$this->nameList[$action['module'] . "." . $action['as']] = $route;
} else {
$this->nameList[$action['as']] = $route;
}
}
// When the route is routing to a controller we will also store the action that
// is used by the route. This will let us reverse route to controllers while
// processing a request and easily generate URLs to the given controllers.
if (isset($action['controller'])) {
$this->addToActionList($action, $route);
}
if (isset($action['module'])) {
$this->addToModuleList($action, $route);
}
if (isset($action['settings_menu'])) {
$this->addToSettingsMenuList($route);
}
}
示例9: extractPermissionFrom
/**
* Extracts the permission configured inside the route action array.
*
* @param Route $route
* @return string|null
*/
private function extractPermissionFrom(Route $route)
{
$parameters = $route->getAction();
if (isset($parameters['permission'])) {
return $parameters['permission'];
}
return null;
}
示例10: __construct
public function __construct(Container $container, Route $route)
{
$this->container = $container;
$opts = $route->getAction();
$method = array_get($opts, self::ROUTE_ACTION_KEY, 'getDefaultMeta');
if (!is_callable([$this, $method])) {
$method = 'getDefaultMeta';
}
$this->method = $method;
}
示例11: handle
/**
* Check the authorization of module access.
*
* @param Request $request
* @param \Closure $next
* @return \Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if (in_array($request->path(), ['admin/login', 'admin/logout'])) {
return $next($request);
}
if ($request->segment(1) == 'admin' && !$this->authorizer->authorize('anomaly.module.users::general.control_panel')) {
abort(403);
}
if (!$this->authorizer->authorize(array_get($this->route->getAction(), 'anomaly.module.users::permission'))) {
if ($message = array_get($this->route->getAction(), 'anomaly.module.users::message')) {
$this->messages->error($message);
}
if ($redirect = array_get($this->route->getAction(), 'anomaly.module.users::redirect')) {
return $this->redirect->to($redirect);
}
abort(403);
}
return $next($request);
}
示例12: handle
/**
* Sets `controller` and `action` application global and view variables, with the names, without affixes/verbs.
* @param \Illuminate\Routing\Route $route
*/
public function handle(\Illuminate\Routing\Route $route)
{
$view = view();
$controller = explode('\\', strtok($route->getAction()['controller'], '@'));
$controller = end($controller);
$controller = strtolower(substr($controller, 0, strpos($controller, 'Controller')));
$action = camel_case(preg_replace('/^(get|post|put|delete|patch)/', '', strtok('')));
$view->share('action', app()['action'] = $action);
$view->share('controller', app()['controller'] = $controller);
}
示例13: handle
/**
* Check the authorization of module access.
*
* @param Request $request
* @param \Closure $next
* @return \Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if (in_array($request->path(), ['admin/login', 'admin/logout'])) {
return $next($request);
}
/* @var UserInterface $user */
$user = $this->auth->user();
$role = array_get($this->route->getAction(), 'anomaly.module.users::role');
$redirect = array_get($this->route->getAction(), 'anomaly.module.users::redirect');
$message = array_get($this->route->getAction(), 'anomaly.module.users::message');
if ($role && (!$user || !$user->hasAnyRole((array) $role))) {
if ($message) {
$this->messages->error($message);
}
if ($redirect) {
return $this->redirect->to($redirect);
}
abort(403);
}
return $next($request);
}
示例14: handle
/**
* Handle the request.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return \Illuminate\Http\RedirectResponse|mixed
*/
public function handle($request, Closure $next)
{
// If the method is not a post - skip.
if (!$request->isMethod('post')) {
return $next($request);
}
// Get the route action.
$action = $this->route->getAction();
// If the route disabled the CSRF - skip.
if (array_get($action, 'csrf') === false) {
return $next($request);
}
/**
* Try validating the CSRF token with the
* base Laravel Middleware.
*/
try {
return parent::handle($request, $next);
} catch (TokenMismatchException $e) {
$this->messages->error('streams::message.csrf_token_mismatch');
return $this->redirector->back();
}
}
示例15: processRoute
/**
* @param \Illuminate\Routing\Route $route
* @param array $bindings
* @param array $headers
* @param bool $withResponse
*
* @return array
*/
public function processRoute($route, $bindings = [], $headers = [], $withResponse = true)
{
$content = '';
$routeAction = $route->getAction();
$routeGroup = $this->getRouteGroup($routeAction['uses']);
$routeDescription = $this->getRouteDescription($routeAction['uses']);
if ($withResponse) {
$response = $this->getRouteResponse($route, $bindings, $headers);
if ($response->headers->get('Content-Type') === 'application/json') {
$content = json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT);
} else {
$content = $response->getContent();
}
}
return $this->getParameters(['id' => md5($route->getUri() . ':' . implode($route->getMethods())), 'resource' => $routeGroup, 'title' => $routeDescription['short'], 'description' => $routeDescription['long'], 'methods' => $route->getMethods(), 'uri' => $route->getUri(), 'parameters' => [], 'response' => $content], $routeAction, $bindings);
}