| Server IP : 149.28.60.191 / Your IP : 216.73.217.128 Web Server : nginx/1.31.1 System : Linux vultr.guest 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : mda ( ) PHP Version : 7.4.33 Disable Function : getmyuid,passthru,leak,listen,diskfreespace,tmpfile,link,shell_exec,dl,exec,system,highlight_file,source,show_source,fpassthru,virtual,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_open,proc_close,proc_nice,proc_terminate,escapeshellcmd,ini_alter,popen,pcntl_exec,socket_accept,socket_bind,socket_clear_error,socket_close,socket_connect,symlink,posix_geteuid,ini_alter,socket_listen,socket_create_listen,socket_read,socket_create_pair,stream_socket_server MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/mda/webapps/mda-restore/wp-includes/php-ai-client/src/Providers/Models/DTO/ |
Upload File : |
<?php
declare (strict_types=1);
namespace WordPress\AiClient\Providers\Models\DTO;
use WordPress\AiClient\Common\AbstractDataTransferObject;
use WordPress\AiClient\Providers\Models\Enums\OptionEnum;
/**
* Represents an option that the implementing code requires the model to support.
*
* This class defines an option that the model must support with a specific value
* for it to be considered suitable for the implementing code's requirements.
*
* @since 0.1.0
*
* @phpstan-type RequiredOptionArrayShape array{
* name: string,
* value: mixed
* }
*
* @extends AbstractDataTransferObject<RequiredOptionArrayShape>
*/
class RequiredOption extends AbstractDataTransferObject
{
public const KEY_NAME = 'name';
public const KEY_VALUE = 'value';
/**
* @var OptionEnum The option name.
*/
protected OptionEnum $name;
/**
* @var mixed The value that the model must support for this option.
*/
protected $value;
/**
* Constructor.
*
* @since 0.1.0
*
* @param OptionEnum $name The option name.
* @param mixed $value The value that the model must support for this option.
*/
public function __construct(OptionEnum $name, $value)
{
$this->name = $name;
$this->value = $value;
}
/**
* Gets the option name.
*
* @since 0.1.0
*
* @return OptionEnum The option name.
*/
public function getName(): OptionEnum
{
return $this->name;
}
/**
* Gets the value that the model must support for this option.
*
* @since 0.1.0
*
* @return mixed The value that the model must support.
*/
public function getValue()
{
return $this->value;
}
/**
* {@inheritDoc}
*
* @since 0.1.0
*/
public static function getJsonSchema(): array
{
return ['type' => 'object', 'properties' => [self::KEY_NAME => ['type' => 'string', 'enum' => OptionEnum::getValues(), 'description' => 'The option name.'], self::KEY_VALUE => ['oneOf' => [['type' => 'string'], ['type' => 'number'], ['type' => 'boolean'], ['type' => 'null'], ['type' => 'array'], ['type' => 'object']], 'description' => 'The value that the model must support for this option.']], 'required' => [self::KEY_NAME, self::KEY_VALUE]];
}
/**
* {@inheritDoc}
*
* @since 0.1.0
*
* @return RequiredOptionArrayShape
*/
public function toArray(): array
{
return [self::KEY_NAME => $this->name->value, self::KEY_VALUE => $this->value];
}
/**
* {@inheritDoc}
*
* @since 0.1.0
*/
public static function fromArray(array $array): self
{
static::validateFromArrayData($array, [self::KEY_NAME, self::KEY_VALUE]);
return new self(OptionEnum::from($array[self::KEY_NAME]), $array[self::KEY_VALUE]);
}
}