本文整理汇总了PHP中Drupal\Core\Cache\CacheableMetadata::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheableMetadata::merge方法的具体用法?PHP CacheableMetadata::merge怎么用?PHP CacheableMetadata::merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Cache\CacheableMetadata
的用法示例。
在下文中一共展示了CacheableMetadata::merge方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addCacheableDependency
/**
* {@inheritdoc}
*/
public function addCacheableDependency($dependency)
{
// A trait doesn't have a constructor, so initialize the cacheability
// metadata if that hasn't happened yet.
if (!isset($this->cacheabilityMetadata)) {
$this->cacheabilityMetadata = new CacheableMetadata();
}
$this->cacheabilityMetadata = $this->cacheabilityMetadata->merge(CacheableMetadata::createFromObject($dependency));
return $this;
}
示例2: testMerge
/**
* @covers ::merge
* @dataProvider providerTestMerge
*
* This only tests at a high level, because it reuses existing logic. Detailed
* tests exist for the existing logic:
*
* @see \Drupal\Tests\Core\Cache\CacheTest::testMergeTags()
* @see \Drupal\Tests\Core\Cache\CacheTest::testMergeMaxAges()
* @see \Drupal\Tests\Core\Cache\CacheContextsTest
*/
public function testMerge(CacheableMetadata $a, CacheableMetadata $b, CacheableMetadata $expected)
{
$cache_contexts_manager = $this->getMockBuilder('Drupal\\Core\\Cache\\CacheContextsManager')->disableOriginalConstructor()->getMock();
$container = new ContainerBuilder();
$container->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container);
$this->assertEquals($expected, $a->merge($b));
}
示例3: merge
/**
* Merges the values of another bubbleable metadata object with this one.
*
* @param \Drupal\Core\Cache\CacheableMetadata $other
* The other bubbleable metadata object.
*
* @return static
* A new bubbleable metadata object, with the merged data.
*/
public function merge(CacheableMetadata $other)
{
$result = parent::merge($other);
if ($other instanceof BubbleableMetadata) {
$result->attached = \Drupal::service('renderer')->mergeAttachments($this->attached, $other->attached);
$result->postRenderCache = NestedArray::mergeDeep($this->postRenderCache, $other->postRenderCache);
}
return $result;
}
示例4: merge
/**
* Merges the values of another bubbleable metadata object with this one.
*
* @param \Drupal\Core\Cache\CacheableMetadata $other
* The other bubbleable metadata object.
*
* @return static
* A new bubbleable metadata object, with the merged data.
*/
public function merge(CacheableMetadata $other)
{
$result = parent::merge($other);
// This is called many times per request, so avoid merging unless absolutely
// necessary.
if ($other instanceof BubbleableMetadata) {
if (empty($this->attachments)) {
$result->attachments = $other->attachments;
} elseif (empty($other->attachments)) {
$result->attachments = $this->attachments;
} else {
$result->attachments = static::mergeAttachments($this->attachments, $other->attachments);
}
}
return $result;
}
示例5: addCacheableDependency
/**
* {@inheritdoc}
*/
public function addCacheableDependency($dependency)
{
$this->cacheabilityMetadata = $this->cacheabilityMetadata->merge(CacheableMetadata::createFromObject($dependency));
return $this;
}