HEX
Server: Apache/2
System: Linux bq-e705.pointdnshere.com 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User: wellmix (1103)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/wellmix/public_html/wp-content/plugins/weglot/vendor/weglot/weglot-php/src/Util/JsonUtil.php
<?php

namespace Weglot\Util;

use Weglot\Client\Api\Enum\WordType;
use Weglot\Client\Api\Exception\InvalidWordTypeException;
use Weglot\Client\Api\WordCollection;
use Weglot\Client\Api\WordEntry;

/**
 * Class JsonUtil
 * @package Weglot\Parser\Util
 */
class JsonUtil
{
    const SEPARATOR = "##";
    /**
     * @param array $data
     * @param string $key
     * @return mixed
     */
    public static function get(array $data, $key)
    {
        if (isset($data[$key])) {
            return $data[$key];
        }
        return null;
    }

    /**
     * @param WordCollection $words
     * @param string $value
     * @throws InvalidWordTypeException
     */
    public static function add(WordCollection $words, $value)
    {
        $words->addOne(new WordEntry($value, WordType::TEXT));
    }

    /**
     * @param WordCollection $words
     * @param mixed $data
     * @param null $index
     * @param int $nextJson
     * @return array
     */
    public static function set(WordCollection $words, $data, $index, &$nextJson)
    {
        $keys = explode( self::SEPARATOR , $index);
        $current = &$data;
        foreach ($keys as $key) {
            $current =  &$current[$key];
        }

        $current = $words[$nextJson]->getWord();
        ++$nextJson;

        return $data;
    }

    public static function setHTML($newHTML, $data, $key)
    {
        $keys = explode(self::SEPARATOR , $key);
        $current = &$data;
        foreach ($keys as $key) {
            $current =  &$current[$key];
        }

        $current = $newHTML;


        return $data;
    }

    public static function setJSONString($jsonString, $data, $key)
    {
        $keys = explode(self::SEPARATOR , $key);
        $current = &$data;
        foreach ($keys as $key) {
            $current =  &$current[$key];
        }

        $current = $jsonString;


        return $data;
    }
}