DefinedTestAccessCheck.php

Contains \Drupal\router_test\Access\DefinedTestAccessCheck.

Namespace

Drupal\router_test\Access

File

drupal/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/Access/DefinedTestAccessCheck.php
View source
<?php

/**
 * @file
 * Contains \Drupal\router_test\Access\DefinedTestAccessCheck.
 */
namespace Drupal\router_test\Access;

use Drupal\Core\Access\AccessCheckInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;

/**
 * Defines an access checker similar to DefaultAccessCheck
 */
class DefinedTestAccessCheck implements AccessCheckInterface {

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {
    return array_key_exists('_test_access', $route
      ->getRequirements());
  }

  /**
   * {@inheritdoc}
   */
  public function access(Route $route, Request $request) {
    if ($route
      ->getRequirement('_test_access') === 'TRUE') {
      return static::ALLOW;
    }
    elseif ($route
      ->getRequirement('_test_access') === 'FALSE') {
      return static::KILL;
    }
    else {
      return static::DENY;
    }
  }

}

Classes

Namesort descending Description
DefinedTestAccessCheck Defines an access checker similar to DefaultAccessCheck