Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Soon/AdvancedCache/Model/Cache/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/app/code/Soon/AdvancedCache/Model/Cache/Processor.php
<?php

namespace Soon\AdvancedCache\Model\Cache;

use Magento\Framework\DataObject;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\View\Element\BlockInterface;
use Magento\Framework\View\Layout\Element;
use Magento\Framework\View\LayoutInterface;
use Soon\AdvancedCache\Model\Engine\Factory;

class Processor extends DataObject implements ProcessorInterface
{

    /**
     * @var LayoutInterface|\Magento\Framework\View\Layout
     */
    private $layout;
    /**
     * @var ManagerInterface
     */
    private $eventManager;
    /**
     * @var Factory
     */
    private $engineFactory;

    public function __construct(
        LayoutInterface $layout,
        ManagerInterface $event,
        Factory $engineFactory
    ) {
        parent::__construct();

        $this->layout = $layout;
        $this->eventManager = $event;
        $this->engineFactory = $engineFactory;
    }

    /**
     * @inheritdoc
     */
    public function cacheBlock(BlockInterface $block, $forceCache = false)
    {
        // Let others update $block info
        $this->eventManager->dispatch('soon_advancedcache_cache_add_before', ['block' => $block]);

        // Nuttin' to cache? Get out!
        if (!$this->canCache($block) && !$forceCache) {
            return;
        }

        $engine = $this->getBlockCacheEngine($block);

        // Retrieve caching engine
        $engine = $this->engineFactory->create($engine);

        // Ask engine to cache the block
        $engine->cacheBlock($block);

        // Let others be informed that caching has been processed
        $this->eventManager->dispatch('soon_advancedcache_cache_add_after', ['block' => $block]);
    }

    /**
     * Can we cache based on the current caching configuration?
     *
     * @return bool
     */
    private function canCache(BlockInterface $block)
    {
        if (!$sacData = $block->getData('soon_advancedcache')) {
            return false;
        }

        return (isset($sacData['active']) && $sacData['active'] === '1');
    }

    /**
     * @param BlockInterface $block
     * @return string
     * @throws \Exception
     */
    private function getBlockCacheEngine(BlockInterface $block)
    {
        if (!$sacData = $block->getData('soon_advancedcache')) {
            $blockName = $this->block->getNameInLayout();
            $msg = 'Block with name "' . $blockName . '" supposes to be cacheable, but empty SAC data provided.';
            throw new \RuntimeException($msg);
        }

        if (isset($sacData['engine'])) {
            return $sacData['engine'];
        }

        return \Soon\AdvancedCache\Model\Engine\Factory::ENGINE_TYPE_STANDARD;
    }
}

Spamworldpro Mini