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/vendor/magento/module-media-gallery-renditions/Plugin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-media-gallery-renditions/Plugin/SetRenditionPath.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\MediaGalleryRenditions\Plugin;

use Magento\Cms\Helper\Wysiwyg\Images;
use Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent;
use Magento\Framework\Exception\LocalizedException;
use Magento\MediaGalleryRenditions\Model\Config;
use Magento\MediaGalleryRenditionsApi\Api\GenerateRenditionsInterface;
use Magento\MediaGalleryRenditionsApi\Api\GetRenditionPathInterface;
use Psr\Log\LoggerInterface;

/**
 * Intercept and set renditions path on PrepareImage
 */
class SetRenditionPath
{
    /**
     * @var GetRenditionPathInterface
     */
    private $getRenditionPath;

    /**
     * @var GenerateRenditionsInterface
     */
    private $generateRenditions;

    /**
     * @var Images
     */
    private $imagesHelper;

    /**
     * @var Config
     */
    private $config;

    /**
     * @var LoggerInterface
     */
    private $log;

    /**
     * @param GetRenditionPathInterface $getRenditionPath
     * @param GenerateRenditionsInterface $generateRenditions
     * @param Images $imagesHelper
     * @param Config $config
     * @param LoggerInterface $log
     */
    public function __construct(
        GetRenditionPathInterface $getRenditionPath,
        GenerateRenditionsInterface $generateRenditions,
        Images $imagesHelper,
        Config $config,
        LoggerInterface $log
    ) {
        $this->getRenditionPath = $getRenditionPath;
        $this->generateRenditions = $generateRenditions;
        $this->imagesHelper = $imagesHelper;
        $this->config = $config;
        $this->log = $log;
    }

    /**
     * Replace the original asset path with rendition path
     *
     * @param GetInsertImageContent $subject
     * @param string $encodedFilename
     * @param bool $forceStaticPath
     * @param bool $renderAsTag
     * @param int|null $storeId
     * @return array
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function beforeExecute(
        GetInsertImageContent $subject,
        string $encodedFilename,
        bool $forceStaticPath,
        bool $renderAsTag,
        ?int $storeId = null
    ): array {
        $arguments = [
            $encodedFilename,
            $forceStaticPath,
            $renderAsTag,
            $storeId
        ];

        if (!$this->config->isEnabled() || !$this->config->isMediaGalleryEnabled()) {
            return $arguments;
        }

        $path = $this->imagesHelper->idDecode($encodedFilename);

        try {
            $this->generateRenditions->execute([$path]);
        } catch (LocalizedException $exception) {
            $this->log->error($exception);
            return $arguments;
        }

        $arguments[0] = $this->imagesHelper->idEncode($this->getRenditionPath->execute($path));

        return $arguments;
    }
}

Spamworldpro Mini