| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare (strict_types=1); 4 namespace WordPress\AiClient\Providers\Models\DTO; 5 6 use WordPress\AiClient\Common\AbstractDataTransferObject; 7 use WordPress\AiClient\Providers\Models\Enums\OptionEnum; 8 /** 9 * Represents an option that the implementing code requires the model to support. 10 * 11 * This class defines an option that the model must support with a specific value 12 * for it to be considered suitable for the implementing code's requirements. 13 * 14 * @since 0.1.0 15 * 16 * @phpstan-type RequiredOptionArrayShape array{ 17 * name: string, 18 * value: mixed 19 * } 20 * 21 * @extends AbstractDataTransferObject<RequiredOptionArrayShape> 22 */ 23 class RequiredOption extends AbstractDataTransferObject 24 { 25 public const KEY_NAME = 'name'; 26 public const KEY_VALUE = 'value'; 27 /** 28 * @var OptionEnum The option name. 29 */ 30 protected OptionEnum $name; 31 /** 32 * @var mixed The value that the model must support for this option. 33 */ 34 protected $value; 35 /** 36 * Constructor. 37 * 38 * @since 0.1.0 39 * 40 * @param OptionEnum $name The option name. 41 * @param mixed $value The value that the model must support for this option. 42 */ 43 public function __construct(OptionEnum $name, $value) 44 { 45 $this->name = $name; 46 $this->value = $value; 47 } 48 /** 49 * Gets the option name. 50 * 51 * @since 0.1.0 52 * 53 * @return OptionEnum The option name. 54 */ 55 public function getName(): OptionEnum 56 { 57 return $this->name; 58 } 59 /** 60 * Gets the value that the model must support for this option. 61 * 62 * @since 0.1.0 63 * 64 * @return mixed The value that the model must support. 65 */ 66 public function getValue() 67 { 68 return $this->value; 69 } 70 /** 71 * {@inheritDoc} 72 * 73 * @since 0.1.0 74 */ 75 public static function getJsonSchema(): array 76 { 77 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]]; 78 } 79 /** 80 * {@inheritDoc} 81 * 82 * @since 0.1.0 83 * 84 * @return RequiredOptionArrayShape 85 */ 86 public function toArray(): array 87 { 88 return [self::KEY_NAME => $this->name->value, self::KEY_VALUE => $this->value]; 89 } 90 /** 91 * {@inheritDoc} 92 * 93 * @since 0.1.0 94 */ 95 public static function fromArray(array $array): self 96 { 97 static::validateFromArrayData($array, [self::KEY_NAME, self::KEY_VALUE]); 98 return new self(OptionEnum::from($array[self::KEY_NAME]), $array[self::KEY_VALUE]); 99 } 100 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |