applies example

use Symfony\Component\HttpFoundation\Request;

/** * Defines the query parameter workspace negotiator. */
class QueryParameterWorkspaceNegotiator extends SessionWorkspaceNegotiator {

  /** * {@inheritdoc} */
  public function applies(Request $request) {
    return is_string($request->query->get('workspace')) && parent::applies($request);
  }

  /** * {@inheritdoc} */
  public function getActiveWorkspace(Request $request) {
    $workspace_id = $request->query->get('workspace');

    if ($workspace_id && ($workspace = $this->workspaceStorage->load($workspace_id))) {
      $this->setActiveWorkspace($workspace);
      return $workspace;
    }


  /** * Returns the site maintenance page if the site is offline. * * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event * The event to process. */
  public function onKernelRequestMaintenance(RequestEvent $event) {
    $request = $event->getRequest();
    $route_match = RouteMatch::createFromRequest($request);
    if ($this->maintenanceMode->applies($route_match)) {
      // Don't cache maintenance mode pages.       \Drupal::service('page_cache_kill_switch')->trigger();

      if (!$this->maintenanceMode->exempt($this->account)) {
        // When the account is not exempt, other subscribers handle request.         $this->eventDispatcher->dispatch($event, MaintenanceModeEvents::MAINTENANCE_MODE_REQUEST);
      }
      else {
        // Display a message if the logged-in user has access to the site in         // maintenance mode. Don't show maintenance message:         // - on AJAX requests.
    else {
      $view = new ViewUI($entity);
    }

    return $view;
  }

  /** * {@inheritdoc} */
  public function applies($definition$name, Route $route) {
    if (parent::applies($definition$name$route)) {
      return !empty($definition['tempstore']) && $definition['type'] === 'entity:view';
    }
    return FALSE;
  }

}

  protected function getProvider(Request $request) {
    foreach ($this->authCollector->getSortedProviders() as $provider_id => $provider) {
      if ($provider->applies($request)) {
        return $provider_id;
      }
    }
  }

  /** * Returns the ID of the challenge provider for a request. * * @param \Symfony\Component\HttpFoundation\Request $request * The incoming request. * * @return string|null * The ID of the first authentication provider which applies to the request. * If no application detects appropriate credentials, then NULL is returned. */

        public function convert($value$definition$name, array $defaults)
        {
            return $this->lazyLoadItself()->convert($value$definition$name$defaults);
        }

        /** * {@inheritdoc} */
        public function applies($definition$name, \Symfony\Component\Routing\Route $route)
        {
            return $this->lazyLoadItself()->applies($definition$name$route);
        }

    }

}
// Make an object to test.     $builder = new ForumListingBreadcrumbBuilder($entity_type_manager$config_factory$forum_manager$translation_manager);

    $route_match = $this->createMock('Drupal\Core\Routing\RouteMatchInterface');
    $route_match->expects($this->once())
      ->method('getRouteName')
      ->willReturn($route_name);
    $route_match->expects($this->any())
      ->method('getParameter')
      ->willReturnMap($parameter_map);

    $this->assertEquals($expected$builder->applies($route_match));
  }

  /** * Provides test data for testApplies(). * * @return array * Array of datasets for testApplies(). Structured as such: * - ForumListBreadcrumbBuilder::applies() expected result. * - ForumListBreadcrumbBuilder::applies() $attributes input array. */
  public function providerTestApplies() {
    
public function applies(RouteMatchInterface $route_match) {
    return TRUE;
  }

  /** * {@inheritdoc} */
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    foreach ($this->negotiators as $negotiator_id) {
      $negotiator = $this->classResolver->getInstanceFromDefinition($negotiator_id);

      if ($negotiator->applies($route_match)) {
        $theme = $negotiator->determineActiveTheme($route_match);
        if ($theme !== NULL && $this->themeAccess->checkAccess($theme)) {
          return $theme;
        }
      }
    }
  }

}
return $this->getActiveWorkspace() !== FALSE;
  }

  /** * {@inheritdoc} */
  public function getActiveWorkspace() {
    if (!isset($this->activeWorkspace)) {
      $request = $this->requestStack->getCurrentRequest();
      foreach ($this->negotiatorIds as $negotiator_id) {
        $negotiator = $this->classResolver->getInstanceFromDefinition($negotiator_id);
        if ($negotiator->applies($request)) {
          // By default, 'view' access is checked when a workspace is activated,           // but it should also be checked when retrieving the currently active           // workspace.           if (($negotiated_workspace = $negotiator->getActiveWorkspace($request)) && $negotiated_workspace->access('view')) {
            $active_workspace = $negotiated_workspace;
            break;
          }
        }
      }

      // If no negotiator was able to determine the active workspace, default to


    private function isWhitelistedController(ControllerEvent $event): bool
    {
        $controllerClass = $this->extractControllerClass($event);

        if (!$controllerClass) {
            return false;
        }

        foreach ($this->whitelists as $whitelist) {
            if ($whitelist->applies($controllerClass)) {
                return true;
            }
        }

        return false;
    }

    /** * @return list<string> */
    private function extractCurrentScopeAnnotation(ControllerEvent $event): array
    {

  public function testApplies(array $definition$name, Route $route$applies) {
    $this->entityTypeManager->expects($this->any())
      ->method('hasDefinition')
      ->willReturnCallback(function D$entity_type) {
        return 'entity_test' == $entity_type;
      });
    $this->assertEquals($applies$this->entityConverter->applies($definition$name$route));
  }

  /** * Provides test data for testApplies() */
  public function providerTestApplies() {
    $data = [];
    $data[] = [['type' => 'entity:foo'], 'foo', new Route('/test/{foo}/bar'), FALSE];
    $data[] = [['type' => 'entity:entity_test'], 'foo', new Route('/test/{foo}/bar'), TRUE];
    $data[] = [['type' => 'entity:entity_test'], 'entity_test', new Route('/test/{entity_test}/bar'), TRUE];
    $data[] = [['type' => 'entity:{entity_test}'], 'entity_test', new Route('/test/{entity_test}/bar'), FALSE];
    

        public function convert($value$definition$name, array $defaults)
        {
            return $this->lazyLoadItself()->convert($value$definition$name$defaults);
        }

        /** * {@inheritdoc} */
        public function applies($definition$name, \Symfony\Component\Routing\Route $route)
        {
            return $this->lazyLoadItself()->applies($definition$name$route);
        }

    }

}
/** * Authenticates user on request. * * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event * The request event. * * @see \Drupal\Core\Authentication\AuthenticationProviderInterface::authenticate() */
  public function onKernelRequestAuthenticate(RequestEvent $event) {
    if ($event->isMainRequest()) {
      $request = $event->getRequest();
      if ($this->authenticationProvider->applies($request)) {
        $account = $this->authenticationProvider->authenticate($request);
        if ($account) {
          $this->accountProxy->setAccount($account);
          return;
        }
      }
    }
  }

  /** * Denies access if authentication provider is not allowed on this route. * * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event * The request event. */
$this->assertEqualsCanonicalizing(['url.path.is_front', 'url.path.parent']$breadcrumb->getCacheContexts());
    $this->assertEqualsCanonicalizing([]$breadcrumb->getCacheTags());
    $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
  }

  /** * Tests the applied method. * * @covers ::applies */
  public function testApplies() {
    $this->assertTrue($this->builder->applies($this->createMock('Drupal\Core\Routing\RouteMatchInterface')));
  }

  /** * Tests the breadcrumb for a user path. * * @covers ::build * @covers ::getRequestForPath */
  public function testBuildWithUserPath() {
    $this->context->expects($this->once())
      ->method('getPathInfo')
      

  }

  /** * {@inheritdoc} */
  public function applies($definition$name, Route $route) {
    if (isset($definition['with_config_overrides']) && $definition['with_config_overrides']) {
      return FALSE;
    }

    if (parent::applies($definition$name$route)) {
      $entity_type_id = substr($definition['type']strlen('entity:'));
      // If the entity type is dynamic, defer checking to self::convert().       if (str_starts_with($entity_type_id, '{')) {
        return TRUE;
      }
      // As we only want to override EntityConverter for ConfigEntities, find       // out whether the current entity is a ConfigEntity.       $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
      if ($entity_type->entityClassImplements(ConfigEntityInterface::class)) {
        return $this->adminContext->isAdminRoute($route);
      }
    }

        public function convert($value$definition$name, array $defaults)
        {
            return $this->lazyLoadItself()->convert($value$definition$name$defaults);
        }

        /** * {@inheritdoc} */
        public function applies($definition$name, \Symfony\Component\Routing\Route $route)
        {
            return $this->lazyLoadItself()->applies($definition$name$route);
        }

    }

}
Home | Imprint | This part of the site doesn't use cookies.