You are here

class RedirectChecker in Global Redirect 8

Redirect checker class.

Hierarchy

Expanded class hierarchy of RedirectChecker

1 file declares its use of RedirectChecker
GlobalredirectSubscriber.php in src/EventSubscriber/GlobalredirectSubscriber.php
Contains \Drupal\globalredirect\EventSubscriber\GlobalredirectSubscriber.
1 string reference to 'RedirectChecker'
globalredirect.services.yml in ./globalredirect.services.yml
globalredirect.services.yml
1 service uses RedirectChecker
globalredirect.checker in ./globalredirect.services.yml
Drupal\globalredirect\RedirectChecker

File

src/RedirectChecker.php, line 18
Contains Drupal\globalredirect\RedirectChecker.

Namespace

Drupal\globalredirect
View source
class RedirectChecker {

  /**
   * @var \Drupal\Core\Config\Config
   */
  protected $config;

  /**
   * @var \Drupal\Core\Access\AccessManager
   */
  protected $accessManager;

  /**
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $account;

  /**
   * @var \Drupal\Core\Routing\RouteProviderInterface
   */
  protected $routeProvider;

  /**
   * @param ConfigFactoryInterface $config
   * @param \Drupal\Core\Access\AccessManager $access_manager
   *   The access manager service.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The account object.
   * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
   *   The route provider service.
   */
  public function __construct(ConfigFactoryInterface $config, AccessManager $access_manager, AccountInterface $account, RouteProviderInterface $route_provider) {
    $this->config = $config
      ->get('globalredirect.settings');
    $this->accessManager = $access_manager;
    $this->account = $account;
    $this->routeProvider = $route_provider;
  }

  /**
   * Checks access to the route.
   *
   * @param string $route_name
   *   The current route name.
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The current request.
   *
   * @return bool
   *   TRUE if access is granted.
   */
  public function canRedirect($route_name, Request $request) {
    $do_redirect = TRUE;

    /** @var \Symfony\Component\Routing\Route $route */
    $route = $this->routeProvider
      ->getRouteByName($route_name);
    if ($this->config
      ->get('access_check')) {
      $do_redirect &= $this->accessManager
        ->check($route, $request, $this->account);
    }
    if ($this->config
      ->get('ignore_admin_path')) {
      $do_redirect &= !(bool) $route
        ->getOption('_admin_route');
    }
    return $do_redirect;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RedirectChecker::$accessManager protected property
RedirectChecker::$account protected property
RedirectChecker::$config protected property
RedirectChecker::$routeProvider protected property
RedirectChecker::canRedirect public function Checks access to the route.
RedirectChecker::__construct public function