本文整理汇总了PHP中Magento\PageCache\Model\Config类的典型用法代码示例。如果您正苦于以下问题:PHP Config类的具体用法?PHP Config怎么用?PHP Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isVarnishEnabled
/**
* Is varnish cache engine enabled
*
* @return bool
*/
protected function isVarnishEnabled()
{
if ($this->isVarnishEnabled === null) {
$this->isVarnishEnabled = $this->_config->getType() == \Magento\PageCache\Model\Config::VARNISH;
}
return $this->isVarnishEnabled;
}
示例2: execute
/**
* @param Observer $observer
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute(Observer $observer)
{
if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && $this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
/** @var \Magento\Customer\Model\Data\Customer $customer */
$customer = $observer->getData('customer');
$customerGroupId = $customer->getGroupId();
$customerGroup = $this->groupRepository->getById($customerGroupId);
$customerTaxClassId = $customerGroup->getTaxClassId();
$this->customerSession->setCustomerTaxClassId($customerTaxClassId);
/** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
$addresses = $customer->getAddresses();
if (isset($addresses)) {
$defaultShippingFound = false;
$defaultBillingFound = false;
foreach ($addresses as $address) {
if ($address->isDefaultBilling()) {
$defaultBillingFound = true;
$this->customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
}
if ($address->isDefaultShipping()) {
$defaultShippingFound = true;
$this->customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
}
if ($defaultShippingFound && $defaultBillingFound) {
break;
}
}
}
}
}
示例3: afterGenerateXml
/**
* After generate Xml
*
* @param \Magento\Framework\View\LayoutInterface $subject
* @param \Magento\Framework\View\LayoutInterface $result
* @return \Magento\Framework\View\LayoutInterface
*/
public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
{
if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) {
$this->checkoutSession->clearStorage();
}
return $result;
}
示例4: testExportVarnishConfigAction
public function testExportVarnishConfigAction()
{
$fileContent = 'some conetnt';
$filename = 'varnish.vcl';
$responseMock = $this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->disableOriginalConstructor()->getMock();
$this->configMock->expects($this->once())->method('getVclFile')->will($this->returnValue($fileContent));
$this->fileFactoryMock->expects($this->once())->method('create')->with($this->equalTo($filename), $this->equalTo($fileContent), $this->equalTo(DirectoryList::VAR_DIR))->will($this->returnValue($responseMock));
$result = $this->action->executeInternal();
$this->assertInstanceOf('Magento\\Framework\\App\\ResponseInterface', $result);
}
示例5: execute
/**
* If Built-In caching is enabled it collects array of tags
* of incoming object and asks to clean cache.
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->_config->isEnabled()) {
$object = $observer->getEvent()->getObject();
if ($object instanceof \Magento\Framework\DataObject\IdentityInterface) {
$tags = $object->getIdentities();
if (!empty($tags)) {
$this->getCache()->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array_unique($tags));
}
}
}
}
示例6: testCheckIfDepersonalize
/**
* @param array $requestResult
* @param bool $moduleManagerResult
* @param bool $cacheConfigResult
* @param bool $layoutResult
* @param bool $can Depersonalize
* @dataProvider checkIfDepersonalizeDataProvider
*/
public function testCheckIfDepersonalize(array $requestResult, $moduleManagerResult, $cacheConfigResult, $layoutResult, $canDepersonalize)
{
$this->requestMock->expects($this->any())->method('isAjax')->willReturn($requestResult['ajax']);
$this->requestMock->expects($this->any())->method('isGet')->willReturn($requestResult['get']);
$this->requestMock->expects($this->any())->method('isHead')->willReturn($requestResult['head']);
$this->moduleManagerMock->expects($this->any())->method('isEnabled')->with('Magento_PageCache')->willReturn($moduleManagerResult);
$this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn($cacheConfigResult);
$layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false);
$layoutMock->expects($this->any())->method('isCacheable')->willReturn($layoutResult);
$object = new DepersonalizeChecker($this->requestMock, $this->moduleManagerMock, $this->cacheConfigMock);
$this->assertEquals($canDepersonalize, $object->checkIfDepersonalize($layoutMock));
}
示例7: execute
/**
* If Built-In caching is enabled it collects array of tags
* of incoming object and asks to clean cache.
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->_config->isEnabled()) {
$object = $observer->getEvent()->getObject();
if ($object instanceof \Magento\Framework\Object\IdentityInterface) {
$tags = $object->getIdentities();
foreach ($tags as $tag) {
$tags[] = preg_replace("~_\\d+\$~", '', $tag);
}
$this->_cache->clean(array_unique($tags));
}
}
}
示例8: aroundDispatch
/**
* @param \Magento\Framework\App\ActionInterface $subject
* @param callable $proceed
* @param \Magento\Framework\App\RequestInterface $request
* @return mixed
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDispatch(\Magento\Framework\App\ActionInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
{
if (!$this->customerSession->isLoggedIn() || !$this->moduleManager->isEnabled('Magento_PageCache') || !$this->cacheConfig->isEnabled() || !$this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
return $proceed($request);
}
$defaultBillingAddress = $this->customerSession->getDefaultTaxBillingAddress();
$defaultShippingAddress = $this->customerSession->getDefaultTaxShippingAddress();
$customerTaxClassId = $this->customerSession->getCustomerTaxClassId();
if (!empty($defaultBillingAddress) || !empty($defaultShippingAddress)) {
$taxRates = $this->taxCalculation->getTaxRates($defaultBillingAddress, $defaultShippingAddress, $customerTaxClassId);
$this->httpContext->setValue('tax_rates', $taxRates, 0);
}
return $proceed($request);
}
示例9: testExecuteWithEmptyTags
public function testExecuteWithEmptyTags()
{
$this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue(true));
$observerObject = $this->getMock('Magento\\Framework\\Event\\Observer');
$observedObject = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
$tags = [];
$eventMock = $this->getMock('Magento\\Framework\\Event', ['getObject'], [], '', false);
$eventMock->expects($this->once())->method('getObject')->will($this->returnValue($observedObject));
$observerObject->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
$this->_configMock->expects($this->once())->method('getType')->will($this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN));
$observedObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags));
$this->_cacheMock->expects($this->never())->method('clean');
$this->_model->execute($observerObject);
}
示例10: testExecute
/**
* @param bool $cacheState
* @param bool $varnishIsEnabled
* @param bool $scopeIsPrivate
* @param int|null $blockTtl
* @param string $expectedOutput
* @dataProvider processLayoutRenderDataProvider
*/
public function testExecute($cacheState, $varnishIsEnabled, $scopeIsPrivate, $blockTtl, $expectedOutput)
{
$eventMock = $this->getMock('Magento\\Framework\\Event', ['getLayout', 'getElementName', 'getTransport'], [], '', false);
$this->_observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
$eventMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->_layoutMock));
$this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
if ($cacheState) {
$eventMock->expects($this->once())->method('getElementName')->will($this->returnValue('blockName'));
$eventMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transport));
$this->_layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
$this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnSelf());
$this->_layoutMock->expects($this->any())->method('getHandles')->will($this->returnValue([]));
$this->_layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->_blockMock));
if ($varnishIsEnabled) {
$this->_blockMock->expects($this->once())->method('getData')->with('ttl')->will($this->returnValue($blockTtl));
$this->_blockMock->expects($this->any())->method('getUrl')->will($this->returnValue('page_cache/block/wrapesi/with/handles/and/other/stuff'));
}
if ($scopeIsPrivate) {
$this->_blockMock->expects($this->once())->method('getNameInLayout')->will($this->returnValue('testBlockName'));
$this->_blockMock->expects($this->once())->method('isScopePrivate')->will($this->returnValue($scopeIsPrivate));
}
$this->_configMock->expects($this->any())->method('getType')->will($this->returnValue($varnishIsEnabled));
}
$this->_model->execute($this->_observerMock);
$this->assertEquals($expectedOutput, $this->_transport['output']);
}
示例11: execute
/**
* Invalidate full page and block cache
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->_config->isEnabled()) {
$this->_typeList->invalidate(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER);
}
$this->_typeList->invalidate(\Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER);
}
示例12: afterExecute
/**
* @param AbstractAction $subject
* @param AbstractAction $result
* @return AbstractAction
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterExecute(AbstractAction $subject, AbstractAction $result)
{
if ($this->config->isEnabled()) {
$this->typeList->invalidate('full_page');
}
return $result;
}
示例13: execute
/**
* Invalidate full page cache
*
* @return void
*/
public function execute()
{
if ($this->_config->isEnabled()) {
$this->_typeList->invalidate('full_page');
}
return $this;
}
示例14: testAfterExecuteInvalidate
public function testAfterExecuteInvalidate()
{
$subject = $this->getMockBuilder('Magento\\Catalog\\Model\\Indexer\\Category\\Product\\AbstractAction')->disableOriginalConstructor()->getMockForAbstractClass();
$result = $this->getMockBuilder('Magento\\Catalog\\Model\\Indexer\\Category\\Product\\AbstractAction')->disableOriginalConstructor()->getMockForAbstractClass();
$this->config->expects($this->once())->method('isEnabled')->willReturn(true);
$this->typeList->expects($this->once())->method('invalidate')->with('full_page');
$this->assertEquals($result, $this->execute->afterExecute($subject, $result));
}
示例15: testAroundDispatchDisabled
/**
* @dataProvider dataProvider
*/
public function testAroundDispatchDisabled($state)
{
$this->configMock->expects($this->any())->method('getType')->will($this->returnValue(null));
$this->versionMock->expects($this->never())->method('process');
$this->stateMock->expects($this->any())->method('getMode')->will($this->returnValue($state));
$this->responseMock->expects($this->never())->method('setHeader');
$this->plugin->aroundDispatch($this->frontControllerMock, $this->closure, $this->requestMock);
}