当前位置: 首页>>代码示例>>PHP>>正文


PHP CacheableMetadata::addCacheTags方法代码示例

本文整理汇总了PHP中Drupal\Core\Cache\CacheableMetadata::addCacheTags方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheableMetadata::addCacheTags方法的具体用法?PHP CacheableMetadata::addCacheTags怎么用?PHP CacheableMetadata::addCacheTags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Cache\CacheableMetadata的用法示例。


在下文中一共展示了CacheableMetadata::addCacheTags方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $result = new FilterProcessResult($text);
     $metadata = new CacheableMetadata();
     $metadata->addCacheTags(['merge:tag']);
     $metadata->addCacheContexts(['user.permissions']);
     $result = $result->merge($metadata);
     return $result;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:12,代码来源:FilterTestCacheMerge.php

示例2: testAddCacheTags

 /**
  * This delegates to Cache::mergeTags(), so just a basic test.
  *
  * @covers ::addCacheTags
  */
 public function testAddCacheTags()
 {
     $metadata = new CacheableMetadata();
     $add_expected = [[[], []], [['foo:bar'], ['foo:bar']], [['foo:baz'], ['foo:bar', 'foo:baz']], [['axx:first', 'foo:baz'], ['axx:first', 'foo:bar', 'foo:baz']], [[], ['axx:first', 'foo:bar', 'foo:baz']], [['axx:first'], ['axx:first', 'foo:bar', 'foo:baz']]];
     foreach ($add_expected as $data) {
         list($add, $expected) = $data;
         $metadata->addCacheTags($add);
         $this->assertEquals($expected, $metadata->getCacheTags());
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:15,代码来源:CacheableMetadataTest.php

示例3: forceLogin

 /**
  * Handles a page request for our forced login route.
  */
 public function forceLogin()
 {
     // TODO: What if CAS is not configured? need to handle that case.
     $query_params = $this->requestStack->getCurrentRequest()->query->all();
     $cas_login_url = $this->casHelper->getServerLoginUrl($query_params);
     $this->casHelper->log("Cas forced login route, redirecting to: {$cas_login_url}");
     // This response is OK to cache, but since the redirect URL is dependent on
     // the configured server settings, we need to add some cache metadata tied
     // to the settings.
     $cacheable_metadata = new CacheableMetadata();
     $cacheable_metadata->addCacheTags(array('config:cas.settings'));
     $response = TrustedRedirectResponse::create($cas_login_url, 302);
     $response->addCacheableDependency($cacheable_metadata);
     return $response;
 }
开发者ID:pulibrary,项目名称:recap,代码行数:18,代码来源:ForceLoginController.php

示例4: getCacheableMetadata

 /**
  * {@inheritdoc}
  */
 public function getCacheableMetadata()
 {
     // The book active trail depends on the node and data attached to it.
     // That information is however not stored as part of the node.
     $cacheable_metadata = new CacheableMetadata();
     if ($node = $this->requestStack->getCurrentRequest()->get('node')) {
         // If the node is part of a book then we can use the cache tag for that
         // book. If not, then it can't be optimized away.
         if (!empty($node->book['bid'])) {
             $cacheable_metadata->addCacheTags(['bid:' . $node->book['bid']]);
         } else {
             $cacheable_metadata->setCacheMaxAge(0);
         }
     }
     return $cacheable_metadata;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:19,代码来源:BookNavigationCacheContext.php

示例5: testForceLogin

 /**
  * Test the forcedLogin redirect.
  *
  * @covers ::forceLogin
  * @covers ::__construct
  */
 public function testForceLogin()
 {
     $request = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
     $query = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ParameterBag');
     $request->query = $query;
     $this->requestStack->expects($this->once())->method('getCurrentRequest')->will($this->returnValue($request));
     $parameters = array('returnto' => 'node/1', 'foo' => 'bar');
     $query->expects($this->once())->method('all')->will($this->returnValue($parameters));
     $this->casHelper->expects($this->once())->method('getServerLoginUrl')->with($this->equalTo($parameters))->will($this->returnValue('https://example.com'));
     $cacheableMetadata = new CacheableMetadata();
     $cacheableMetadata->addCacheTags(array('config:cas.settings'));
     $expected_response = new TrustedRedirectResponse('https://example.com', 302);
     $expected_response->addCacheableDependency($cacheableMetadata);
     $force_login_controller = new ForceLoginController($this->casHelper, $this->requestStack);
     $response = $force_login_controller->forceLogin();
     $this->assertEquals($expected_response, $response);
 }
开发者ID:pulibrary,项目名称:recap,代码行数:23,代码来源:ForceLoginControllerTest.php

示例6: processOutbound

 /**
  * Implements Drupal\Core\PathProcessor\OutboundPathProcessorInterface::processOutbound().
  */
 public function processOutbound($path, &$options = array(), Request $request = NULL, CacheableMetadata $cacheable_metadata = NULL)
 {
     // Rewrite user/uid to user/username.
     if (preg_match('!^/user/([0-9]+)(/.*)?!', $path, $matches)) {
         if ($account = User::load($matches[1])) {
             $matches += array(2 => '');
             $path = '/user/' . $account->getUsername() . $matches[2];
             if ($cacheable_metadata) {
                 $cacheable_metadata->addCacheTags($account->getCacheTags());
             }
         }
     }
     // Rewrite forum/ to community/.
     if ($path == '/forum' || strpos($path, '/forum/') === 0) {
         $path = '/community' . substr($path, 5);
     }
     return $path;
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:21,代码来源:PathProcessorTest.php

示例7: processOutbound

 /**
  * {@inheritdoc}
  */
 public function processOutbound($path, &$options = array(), Request $request = NULL, CacheableMetadata $cacheable_metadata = NULL)
 {
     if ($request) {
         // The following values are not supposed to change during a single page
         // request processing.
         if (!isset($this->queryRewrite)) {
             if ($this->currentUser->isAnonymous()) {
                 $languages = $this->languageManager->getLanguages();
                 $config = $this->config->get('language.negotiation')->get('session');
                 $this->queryParam = $config['parameter'];
                 $this->queryValue = $request->query->has($this->queryParam) ? $request->query->get($this->queryParam) : NULL;
                 $this->queryRewrite = isset($languages[$this->queryValue]);
             } else {
                 $this->queryRewrite = FALSE;
             }
         }
         // If the user is anonymous, the user language negotiation method is
         // enabled, and the corresponding option has been set, we must preserve
         // any explicit user language preference even with cookies disabled.
         if ($this->queryRewrite) {
             if (isset($options['query']) && is_string($options['query'])) {
                 $query = array();
                 parse_str($options['query'], $query);
                 $options['query'] = $query;
             }
             if (!isset($options['query'][$this->queryParam])) {
                 $options['query'][$this->queryParam] = $this->queryValue;
             }
             if ($cacheable_metadata) {
                 // Cached URLs that have been processed by this outbound path
                 // processor must be:
                 $cacheable_metadata->addCacheTags($this->config->get('language.negotiation')->getCacheTags())->addCacheContexts(['url.query_args:' . $this->queryParam]);
             }
         }
     }
     return $path;
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:40,代码来源:LanguageNegotiationSession.php


注:本文中的Drupal\Core\Cache\CacheableMetadata::addCacheTags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。