Initial import
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
class GeminiParameter {
|
||||
public $name;
|
||||
public $type;
|
||||
public $description;
|
||||
public $required;
|
||||
public $children;
|
||||
public $enum;
|
||||
|
||||
public function __construct($n, $t, $d, $r = false) {
|
||||
$this->name = $n;
|
||||
$this->type = $t;
|
||||
$this->description = $d;
|
||||
$this->required = $r;
|
||||
$this->children = [];
|
||||
$this->enum = [];
|
||||
}
|
||||
|
||||
public function add_enum($e) {
|
||||
$this->enum[] = $e;
|
||||
}
|
||||
|
||||
public function add_child($n, $t, $d, $r = false) {
|
||||
$p = new GeminiParameter($n, $t, $d, $r);
|
||||
$this->children[$n] = $p;
|
||||
return $p;
|
||||
}
|
||||
|
||||
public function get_object() {
|
||||
$o = new stdClass;
|
||||
$o->type = $this->type;
|
||||
$o->description = $this->description;
|
||||
switch ($this->type) {
|
||||
case "string":
|
||||
if (count($this->enum) > 0) {
|
||||
$o->format = "enum";
|
||||
$o->enum = $this->enum;
|
||||
}
|
||||
break;
|
||||
case "object":
|
||||
$o->properties = [];
|
||||
$o->required = [];
|
||||
foreach ($this->children as $cn=>$c) {
|
||||
$o->properties[$cn] = $c->get_object();
|
||||
if ($c->required) {
|
||||
$o->required[] = $cn;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
return $o;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user