HEX
Server: Apache
System: Linux webm014.cluster128.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User: circuix (152771)
PHP: 8.0.30
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/circuix/adrRc/wp-content/plugins/weglot/vendor/weglot/weglot-php/src/Client/Api/WordEntry.php
<?php

namespace Weglot\Client\Api;

use Weglot\Client\Api\Enum\WordType;
use Weglot\Client\Api\Exception\InvalidWordTypeException;
use Weglot\Client\Api\Shared\AbstractCollectionEntry;

/**
 * Class WordEntry
 * @package Weglot\Client\Api
 */
class WordEntry extends AbstractCollectionEntry
{
    /**
     * @var string
     */
    protected $word;

    /**
     * @var int
     */
    protected $type = WordType::TEXT;

    /**
     * WordEntry constructor.
     * @param $word
     * @param int $type
     * @throws InvalidWordTypeException
     */
    public function __construct($word, $type = WordType::TEXT)
    {
        $this->setWord($word)
            ->setType($type);
    }

    /**
     * @param string $word
     * @return $this
     */
    public function setWord($word)
    {
        $this->word = $word;

        return $this;
    }

    /**
     * @return string
     */
    public function getWord()
    {
        return $this->word;
    }

    /**
     * Set type of word you gonna translate.
     * Returns false if type is incorrect.
     *
     * @param $type
     * @return $this
     * @throws InvalidWordTypeException
     */
    public function setType($type)
    {
        /**
         * Thoses WordType::__MIN and WordType::__MAX values are
         * only used to check if given type is okay according to
         * what we have in WordType.
         *
         * @see src/Client/Api/Enum/WordType.php
         */
        if (!($type >= WordType::__MIN && $type <= WordType::__MAX)) {
            throw new InvalidWordTypeException();
        }
        $this->type = $type;

        return $this;
    }

    /**
     * @return int
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * {@inheritdoc}
     */
    public function jsonSerialize()
    {
        return [
            't' => $this->getType(),
            'w' => $this->getWord()
        ];
    }
}