Example #1
0
 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);
 }
Example #2
0
 /**
  * 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');
 }
Example #3
0
 /**
  * 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;
 }
 /**
  * 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);
 }
function getControllerName()
{
    $route = new Route();
    print $route->getActionName();
    print "<br />";
    print $route->getAction();
}
Example #6
0
 /**
  * @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;
 }
 /**
  * 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));
 }
 /**
  * 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);
     }
 }
 /**
  * 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;
 }
Example #10
0
 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;
 }
 /**
  * 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);
 }
Example #12
0
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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();
     }
 }
 /**
  * @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);
 }
Example #16
0
 public function showCollection(Route $route, Router $router)
 {
     // We extract the params not set in the query from the URL
     $queryParams = $route->parameters();
     // Figure out the page from the route URL parameters
     $page = max(1, $route->getParameter('page'));
     $routeParams = $route->getAction();
     $query = $routeParams['query'];
     $articles = PressFacade::query($query, $queryParams);
     if (0 === $articles->count() && $page !== 1) {
         return abort(404);
     }
     // create a paginator if required
     if ($routeParams['paginate']) {
         $page_size = PressFacade::getConf('default_page_size');
         $paginator = $articles->getPaginator($page_size);
         $articles = $articles->forPage($page, $page_size);
     } else {
         $paginator = $articles->getPaginator(999999);
     }
     // decide the view. If it is provided with the query options, just use
     // it. if it is provided with a theme wildcard, use the default theme
     // else try to find a 'collection' view in the default theme.
     // Also, the user can set a theme to load the assets from.
     $theme = array_get($routeParams, 'theme', PressFacade::getConf('theme'));
     if (isset($routeParams['view'])) {
         $viewName = str_replace('_::', "{$theme}::", $routeParams['view']);
         $view = View::make($viewName);
     } else {
         $view = View::make("{$theme}::collection");
     }
     // paginator base path
     $baseUrlParamNames = $this->getRouteParamNames($routeParams['base_route'], $router);
     $baseUrlParams = array_only($queryParams, $baseUrlParamNames);
     $basePath = \URL::route($routeParams['base_route'], $baseUrlParams);
     $paginator->setBasePath($basePath);
     // metadata from the page can be defined trough the route
     $meta = (object) array_get($routeParams, 'meta', []);
     return $view->with('meta', SEO::getMeta())->with('articles', $articles)->with('cacheInfo', PressFacade::editingCacheInfo())->with('themeAssets', PressFacade::getThemeAssets($theme))->with('paginator', $paginator);
 }
 /**
  * Determine if a route is protected.
  *
  * @param  \Illuminate\Routing\Route  $route
  * @return bool
  */
 protected function routeIsProtected(Route $route)
 {
     $action = $route->getAction();
     return in_array('protected', $action, true) || array_get($action, 'protected') === true;
 }
 /**
  * Add the necessary where clauses to the route based on its initial registration.
  *
  * @param  \Illuminate\Routing\Route  $route
  * @return \Illuminate\Routing\Route
  */
 protected function addWhereClausesToRoute($route)
 {
     $route->where(array_merge($this->patterns, array_get($route->getAction(), 'where', [])));
     return $route;
 }
Example #19
0
 /**
  * Merge the group stack with the controller action.
  *
  * @param  \Illuminate\Routing\Route  $route
  * @return void
  */
 protected function mergeController($route)
 {
     $action = $this->mergeWithLastGroup($route->getAction());
     $route->setAction($action);
 }
 /**
  * Handle the redirect.
  *
  * @param Route                       $route
  * @param RedirectResponse            $response
  * @param RedirectRepositoryInterface $redirects
  * @return \Illuminate\Http\RedirectResponse
  */
 public function handle(Route $route, RedirectResponse $response, RedirectRepositoryInterface $redirects)
 {
     return $response->create($redirects->find(array_get($route->getAction(), 'redirect')));
 }
Example #21
0
 protected function getStepFromRoute(Route $route)
 {
     $controllerMethod = $route->getAction()['controller'];
     list($controller, $method) = explode('@', $controllerMethod);
     return preg_replace('/^(get|post)_/', '', snake_case($method));
 }
 /**
  * 현재 요청에 해당하는 관리페이지 메뉴를 찾는다.
  *
  * @param Route $route 현재 요청에 매칭된 route
  *
  * @return void
  */
 protected function setSelectedMenu(Route $route)
 {
     $selectedMenuIds = array_get($route->getAction(), 'settings_menu', []);
     if (count($selectedMenuIds) === 0) {
         return;
     }
     $selectedMenuIds = (array) $selectedMenuIds;
     foreach ($selectedMenuIds as $selectedMenuId) {
         $selected = $this->menuList[$selectedMenuId];
         do {
             $selected->setSelected(true);
             $selected = $selected->getParent();
         } while ($selected);
     }
     $this->selectedMenu = $this->menuList[end($selectedMenuIds)];
 }
 public function parseParameters(Route $route)
 {
     $parameters = $route->parameters();
     $parameters['_route'] = $this->request->getPathInfo();
     $action = $route->getAction();
     // Controller@action
     if (is_string($action)) {
         list($parameters['_controller'], $parameters['action']) = explode('@', $action[0]);
         return $parameters;
     } else {
         if (isset($action['controller'])) {
             list($parameters['_controller'], $parameters['action']) = explode('@', $action['controller']);
             return $parameters;
         } else {
             if (isset($action['uses']) && !empty($action['uses'])) {
                 // Callable
                 if (is_callable($action['uses'])) {
                     $parameters['_controller'] = $action['uses'];
                     $parameters['action'] = $action['uses'];
                     return $parameters;
                     // 'uses' => 'Controller@action'
                 } else {
                     if (is_string($action['uses']) && strpos($action['uses'], '@') !== false) {
                         list($parameters['_controller'], $parameters['action']) = explode('@', $action['uses']);
                         return $parameters;
                     }
                 }
             }
         }
     }
     throw new \RuntimeException('Unable to parse laravel route parameters');
 }
 /**
  * Verify if route has a locale
  * 
  * @param \Illuminate\Routing\Route  $route
  * @param string $locale
  * @return boolean
  */
 public function hasRouteLocale($route, $locale)
 {
     if ((in_array('all', $route->getAction()['locales']) || in_array($locale, $route->getAction()['locales'])) && in_array($locale, $this->localizer->getAvailable())) {
         return true;
     }
     return false;
 }
Example #25
0
 /**
  * getRouteModule
  *
  * @param Route $route route
  *
  * @return mixed
  */
 private function getRouteModule(Route $route)
 {
     $actions = $route->getAction();
     return $actions['module'];
 }
 /**
  * Determine if the route is routing to a controller.
  *
  * @param  Illuminate\Routing\Route  $action
  * @return bool
  */
 protected function routingToController(Route $route)
 {
     return is_string(array_get($route->getAction(), 'controller'));
 }
Example #27
0
 /**
  * Get the scopes of a route.
  *
  * @param  \Illuminate\Routing\Route $route
  *
  * @return string
  */
 protected function getScopes($route)
 {
     $scopes = array_get($route->getAction(), 'scopes');
     return is_array($scopes) ? implode(', ', $scopes) : $scopes;
 }
 /**
  * Get the routes scopes.
  *
  * @param  \Illuminate\Routing\Route  $route
  * @return array
  */
 protected function getRouteScopes(Route $route)
 {
     $action = $route->getAction();
     return isset($action['scopes']) ? (array) $action['scopes'] : [];
 }
Example #29
0
 /**
  * Merge the group stack with the controller action.
  *
  * @param  \Illuminate\Routing\Route  $route
  * @return void
  */
 protected function mergeGroupAttributesIntoRoute($route)
 {
     $action = $this->mergeWithLastGroup($route->getAction());
     $route->setAction($action);
 }
Example #30
0
 /**
  * Determine if a route is targetting the API.
  *
  * @param  \Illuminate\Routing\Route  $route
  * @return bool
  */
 public function routeTargettingApi($route)
 {
     $key = array_search('api', $route->getAction(), true);
     return is_numeric($key);
 }