當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Route::getRequirement方法代碼示例

本文整理匯總了PHP中Symfony\Component\Routing\Route::getRequirement方法的典型用法代碼示例。如果您正苦於以下問題:PHP Route::getRequirement方法的具體用法?PHP Route::getRequirement怎麽用?PHP Route::getRequirement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Routing\Route的用法示例。


在下文中一共展示了Route::getRequirement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: access

 /**
  * Checks access to the route based on the _access parameter.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route)
 {
     if ($route->getRequirement('_access') === 'TRUE') {
         return AccessResult::allowed();
     } elseif ($route->getRequirement('_access') === 'FALSE') {
         return AccessResult::forbidden();
     } else {
         return AccessResult::neutral();
     }
 }
開發者ID:sarahwillem,項目名稱:OD8,代碼行數:19,代碼來源:DefaultAccessCheck.php

示例2: access

 /**
  * Checks access to the route based on the _access parameter.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  *
  * @return string
  *   A \Drupal\Core\Access\AccessInterface constant value.
  */
 public function access(Route $route)
 {
     if ($route->getRequirement('_access') === 'TRUE') {
         return static::ALLOW;
     } elseif ($route->getRequirement('_access') === 'FALSE') {
         return static::KILL;
     } else {
         return static::DENY;
     }
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:19,代碼來源:DefaultAccessCheck.php

示例3: testRequirements

 public function testRequirements()
 {
     $route = new Route('/:foo');
     $route->setRequirements(array('foo' => '\\d+'));
     $this->assertEquals(array('foo' => '\\d+'), $route->getRequirements(), '->setRequirements() sets the requirements');
     $this->assertEquals('\\d+', $route->getRequirement('foo'), '->getRequirement() returns a requirement');
     $this->assertNull($route->getRequirement('bar'), '->getRequirement() returns null if a requirement is not defined');
     $route->setRequirements(array('foo' => '^\\d+$'));
     $this->assertEquals('\\d+', $route->getRequirement('foo'), '->getRequirement() removes ^ and $ from the pattern');
     $this->assertEquals($route, $route->setRequirements(array()), '->setRequirements() implements a fluent interface');
 }
開發者ID:netixpro,項目名稱:symfony,代碼行數:11,代碼來源:RouteTest.php

示例4: testRequirements

 public function testRequirements()
 {
     $route = new Route('/{foo}');
     $route->setRequirements(array('foo' => '\\d+'));
     $this->assertEquals(array('foo' => '\\d+'), $route->getRequirements(), '->setRequirements() sets the requirements');
     $this->assertEquals('\\d+', $route->getRequirement('foo'), '->getRequirement() returns a requirement');
     $this->assertNull($route->getRequirement('bar'), '->getRequirement() returns null if a requirement is not defined');
     $route->setRequirements(array('foo' => '^\\d+$'));
     $this->assertEquals('\\d+', $route->getRequirement('foo'), '->getRequirement() removes ^ and $ from the pattern');
     $this->assertEquals($route, $route->setRequirements(array()), '->setRequirements() implements a fluent interface');
     // test that an array requirement throws an exception
     $this->setExpectedException('InvalidArgumentException');
     $route->setRequirements(array('foo' => array('bar', 'baz')));
 }
開發者ID:notbrain,項目名稱:symfony,代碼行數:14,代碼來源:RouteTest.php

示例5: access

 /**
  * {@inheritdoc}
  */
 public function access(Route $route, AccountInterface $account, Request $request)
 {
     $_entity_revision = $request->attributes->get('_entity_revision');
     $operation = $route->getRequirement('_entity_access_revision');
     list(, $operation) = explode('.', $operation, 2);
     return AccessResult::allowedIf($_entity_revision && $this->checkAccess($_entity_revision, $account, $operation))->cachePerPermissions();
 }
開發者ID:darrylri,項目名稱:protovbmwmo,代碼行數:10,代碼來源:EntityRevisionRouteAccessChecker.php

示例6: access

 /**
  * Checks if the user has access to underlying storage for a Panels display.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     $panels_storage_type = $route_match->getParameter('panels_storage_type');
     $panels_storage_id = $route_match->getParameter('panels_storage_id');
     $op = $route->getRequirement('_panels_storage_access');
     return $this->panelsStorage->access($panels_storage_type, $panels_storage_id, $op, $account);
 }
開發者ID:neeravbm,項目名稱:unify-d8,代碼行數:20,代碼來源:PanelsStorageAccess.php

示例7: access

 /**
  * Checks access for the account and route using the custom access checker.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match object to be checked.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The account being checked.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     $callable = $this->controllerResolver->getControllerFromDefinition($route->getRequirement('_custom_access'));
     $arguments_resolver = $this->argumentsResolverFactory->getArgumentsResolver($route_match, $account);
     $arguments = $arguments_resolver->getArguments($callable);
     return call_user_func_array($callable, $arguments);
 }
開發者ID:ddrozdik,項目名稱:dmaps,代碼行數:18,代碼來源:CustomAccessCheck.php

示例8: access

 /**
  * Checks translation access for the entity and operation on the given route.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param string $source
  *   (optional) For a create operation, the language code of the source.
  * @param string $target
  *   (optional) For a create operation, the language code of the translation.
  * @param string $language
  *   (optional) For an update or delete operation, the language code of the
  *   translation being updated or deleted.
  * @param string $entity_type_id
  *   (optional) The entity type ID.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL, $entity_type_id = NULL)
 {
     /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     if ($entity = $route_match->getParameter($entity_type_id)) {
         if ($account->hasPermission('translate any entity')) {
             return AccessResult::allowed()->cachePerRole();
         }
         $operation = $route->getRequirement('_access_content_translation_manage');
         /* @var \Drupal\content_translation\ContentTranslationHandlerInterface $handler */
         $handler = $this->entityManager->getHandler($entity->getEntityTypeId(), 'translation');
         // Load translation.
         $translations = $entity->getTranslationLanguages();
         $languages = $this->languageManager->getLanguages();
         switch ($operation) {
             case 'create':
                 $source_language = $this->languageManager->getLanguage($source) ?: $entity->language();
                 $target_language = $this->languageManager->getLanguage($target) ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
                 $is_new_translation = $source_language->getId() != $target_language->getId() && isset($languages[$source_language->getId()]) && isset($languages[$target_language->getId()]) && !isset($translations[$target_language->getId()]);
                 return AccessResult::allowedIf($is_new_translation)->cachePerRole()->cacheUntilEntityChanges($entity)->andIf($handler->getTranslationAccess($entity, $operation));
             case 'update':
             case 'delete':
                 $language = $this->languageManager->getLanguage($language) ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
                 $has_translation = isset($languages[$language->getId()]) && $language->getId() != $entity->getUntranslated()->language()->getId() && isset($translations[$language->getId()]);
                 return AccessResult::allowedIf($has_translation)->cachePerRole()->cacheUntilEntityChanges($entity)->andIf($handler->getTranslationAccess($entity, $operation));
         }
     }
     // No opinion.
     return AccessResult::neutral();
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:51,代碼來源:ContentTranslationManageAccessCheck.php

示例9: access

 /**
  * Checks access to create an entity of any bundle for the given route.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parameterized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     $entity_type_id = $route->getRequirement($this->requirementsKey);
     $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
     $access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type_id);
     // In case there is no "bundle" entity key, check create access with no
     // bundle specified.
     if (!$entity_type->hasKey('bundle')) {
         return $access_control_handler->createAccess(NULL, $account, [], TRUE);
     }
     $access = AccessResult::neutral();
     $bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id));
     // Include list cache tag as access might change if more bundles are added.
     if ($entity_type->getBundleEntityType()) {
         $access->addCacheTags($this->entityTypeManager->getDefinition($entity_type->getBundleEntityType())->getListCacheTags());
         // Check if the user is allowed to create new bundles. If so, allow
         // access, so the add page can show a link to create one.
         // @see \Drupal\Core\Entity\Controller\EntityController::addPage()
         $bundle_access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type->getBundleEntityType());
         $access = $access->orIf($bundle_access_control_handler->createAccess(NULL, $account, [], TRUE));
         if ($access->isAllowed()) {
             return $access;
         }
     }
     // Check whether an entity of any bundle may be created.
     foreach ($bundles as $bundle) {
         $access = $access->orIf($access_control_handler->createAccess($bundle, $account, [], TRUE));
         // In case there is a least one bundle user can create entities for,
         // access is allowed.
         if ($access->isAllowed()) {
             break;
         }
     }
     return $access;
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:48,代碼來源:EntityCreateAnyAccessCheck.php

示例10: access

 /**
  * Checks routing access for the node revision.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param int $node_revision
  *   (optional) The node revision ID. If not specified, but $node is, access
  *   is checked for that object's revision.
  * @param \Drupal\node\NodeInterface $node
  *   (optional) A node object. Used for checking access to a node's default
  *   revision when $node_revision is unspecified. Ignored when $node_revision
  *   is specified. If neither $node_revision nor $node are specified, then
  *   access is denied.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, AccountInterface $account, $node_revision = NULL, NodeInterface $node = NULL)
 {
     if ($node_revision) {
         $node = $this->nodeStorage->loadRevision($node_revision);
     }
     $operation = $route->getRequirement('_access_node_revision');
     return AccessResult::allowedIf($node && $this->checkAccess($node, $account, $operation))->cachePerPermissions();
 }
開發者ID:HakS,項目名稱:drupal8_training,代碼行數:27,代碼來源:NodeRevisionAccessCheck.php

示例11: access

 /**
  * Checks routing access for the support_ticket revision.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param int $support_ticket_revision
  *   (optional) The support_ticket revision ID. If not specified, but
  *   $support_ticket is, access is checked for that object's revision.
  * @param \Drupal\support_ticket\SupportTicketInterface $support_ticket
  *   (optional) A support_ticket object. Used for checking access to a
  *   support_ticket's default revision when $support_ticket_revision is
  *   unspecified. Ignored when $support_ticket_revision is specified. If neither
  *   $support_ticket_revision nor $support_ticket are specified, then access is
  *   denied.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, AccountInterface $account, $support_ticket_revision = NULL, SupportTicketInterface $support_ticket = NULL)
 {
     if ($support_ticket_revision) {
         $support_ticket = $this->supportTicketStorage->loadRevision($support_ticket_revision);
     }
     $operation = $route->getRequirement('_access_support_ticket_revision');
     return AccessResult::allowedIf($support_ticket && $this->checkAccess($support_ticket, $account, $operation))->cachePerPermissions();
 }
開發者ID:justincletus,項目名稱:webdrupalpro,代碼行數:28,代碼來源:SupportTicketRevisionAccessCheck.php

示例12: access

 /**
  * Checks routing access for the node revision.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param int $node_revision
  *   (optional) The node revision ID. If not specified, but $node is, access
  *   is checked for that object's revision.
  * @param \Drupal\node\NodeInterface $node
  *   (optional) A node object. Used for checking access to a node's default
  *   revision when $node_revision is unspecified. Ignored when $node_revision
  *   is specified. If neither $node_revision nor $node are specified, then
  *   access is denied.
  *
  * @return string
  *   A \Drupal\Core\Access\AccessInterface constant value.
  */
 public function access(Route $route, AccountInterface $account, $node_revision = NULL, NodeInterface $node = NULL)
 {
     if ($node_revision) {
         $node = $this->nodeStorage->loadRevision($node_revision);
     }
     $operation = $route->getRequirement('_access_node_revision');
     return $node && $this->checkAccess($node, $account, $operation) ? static::ALLOW : static::DENY;
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:27,代碼來源:NodeRevisionAccessCheck.php

示例13: handleRouteRequirements

 /**
  * {@inheritDoc}
  */
 protected function handleRouteRequirements($pathinfo, $name, Route $route)
 {
     // check HTTP scheme requirement
     $scheme = $route->getRequirement('_scheme');
     if ($scheme && $this->context->getScheme() !== $scheme) {
         return array(self::ROUTE_MATCH, $this->redirect($pathinfo, $name, $scheme));
     }
     return array(self::REQUIREMENT_MATCH, null);
 }
開發者ID:marchyoung,項目名稱:FrameworkBenchmarks,代碼行數:12,代碼來源:RedirectableUrlMatcher.php

示例14: access

 /**
  * {@inheritdoc}
  */
 public function access(Route $route, AccountInterface $account, RouteMatchInterface $route_match, $entity_revision = NULL, $_entity_revision = NULL)
 {
     $entity = $_entity_revision ?: $this->extractEntityFromRouteMatch($route_match);
     if ($entity_revision) {
         $entity = $this->entityManager->getStorage($entity->getEntityTypeId())->loadRevision($entity_revision);
     }
     $operation = $route->getRequirement('_entity_access_revision');
     list(, $operation) = explode('.', $operation, 2);
     return AccessResult::allowedIf($entity && $this->checkAccess($entity, $account, $operation))->cachePerPermissions();
 }
開發者ID:heddn,項目名稱:content_entity_base,代碼行數:13,代碼來源:EntityRevisionRouteAccessChecker.php

示例15: access

 /**
  * {@inheritdoc}
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     // Backup the original requirements.
     $original_requirements = $route->getRequirements();
     // Replace it with our entity access value and run the parent access check.
     $route->setRequirement('_entity_access', $route->getRequirement('_page_access'));
     $access = parent::access($route, $route_match, $account);
     // Restore the original requirements.
     $route->setRequirements($original_requirements);
     return $access;
 }
開發者ID:nB-MDSO,項目名稱:mdso-d8blog,代碼行數:14,代碼來源:PageAccessCheck.php


注:本文中的Symfony\Component\Routing\Route::getRequirement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。