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/amasty/shopby-seo/Model/SeoOptionsModifier/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/amasty/shopby-seo/Model/SeoOptionsModifier/UniqueBuilder.php
<?php

declare(strict_types=1);

/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Shop by Seo for Magento 2 (System)
 */

namespace Amasty\ShopbySeo\Model\SeoOptionsModifier;

use Amasty\ShopbySeo\Helper\Data;
use Magento\Catalog\Model\Product\Url as ProductUrl;

class UniqueBuilder
{
    public const DEFAULT_FORMAT = '-';

    /**
     * @var array
     */
    private $cache = [];

    /**
     * @var Data
     */
    private $seoHelper;

    /**
     * @var ProductUrl
     */
    private $productUrl;

    public function __construct(Data $seoHelper, ProductUrl $productUrl)
    {
        $this->seoHelper = $seoHelper;
        $this->productUrl = $productUrl;
    }

    public function execute(string $value, string $optionId = '', bool $forceUniqueValue = false): string
    {
        $uniqueKey = array_search($optionId, $this->cache);
        if ($uniqueKey !== false) {
            return (string)$uniqueKey;
        }

        // @codingStandardsIgnoreLine
        $value = html_entity_decode($value, ENT_QUOTES);
        $formattedValue = $this->productUrl->formatUrlKey($value) ?: self::DEFAULT_FORMAT;
        $formattedValue = str_replace('-', $this->seoHelper->getSpecialChar(), $formattedValue);

        $unique = $formattedValue;

        if (!$this->seoHelper->isIncludeAttributeName() || $forceUniqueValue) {
            $i = 1;
            while (array_key_exists($unique, $this->cache)) {
                if ($this->cache[$unique] !== $optionId) {
                    $unique = $formattedValue . $this->seoHelper->getSpecialChar() . ($i++);
                }
            }
        }

        $this->cache[$unique] = $optionId;

        return (string)$unique;
    }

    public function clear(): void
    {
        $this->cache = [];
    }
}

Spamworldpro Mini