3 namespace dokuwiki\Remote\OpenApiDoc
;
11 * @param string $typehint The typehint as read from the docblock
12 * @param string $context A fully qualified class name in which context the typehint is used
14 public function __construct($typehint, $context = '')
16 $this->typehint
= $typehint;
17 $this->context
= $context;
21 * Return the typehint as read from the docblock
25 public function __toString()
27 return $this->typehint
;
31 * Return the base type
33 * This is the type this variable is. Eg. a string[] is an array.
37 public function getBaseType()
39 $typehint = $this->typehint
;
41 if (str_ends_with($typehint, '[]')) {
45 if (in_array($typehint, ['boolean', 'false', 'true'])) {
49 if (in_array($typehint, ['integer', 'date'])) {
53 if ($typehint === 'file') {
57 // fully qualified class name
58 if ($typehint[0] === '\\') {
59 return ltrim($typehint, '\\');
62 // relative class name, try to resolve
63 if ($this->context
&& ctype_upper($typehint[0])) {
64 return ClassResolver
::getInstance()->resolve($typehint, $this->context
);
71 * Return a primitive type understood by the XMLRPC server
73 * @param string $typehint
76 public function getJSONRPCType()
78 return $this->getBaseType();
82 * Get the base type as one of the supported OpenAPI types
84 * Formats (eg. int32 or double) are not supported
86 * @link https://swagger.io/docs/specification/data-models/data-types/
89 public function getOpenApiType()
91 switch ($this->getBaseType()) {
111 * If this is an array, return the type of the array elements
113 * @return Type|null null if this is not a typed array
115 public function getSubType()
117 $type = $this->typehint
;
118 if (!str_ends_with($type, '[]')) {
121 $type = substr($type, 0, -2);
122 return new Type($type, $this->context
);
126 * Return a type understood by the XMLRPC server
130 public function getXMLRPCType()
132 $type = $this->typehint
;
135 if (in_array($type, ['date', 'file', 'struct'])) {
139 $type = $this->getBaseType($this->typehint
);
142 if (in_array($type, ['int', 'string', 'double', 'bool', 'array'])) {
146 // everything else is an object
147 return 'object'; //should this return 'struct'?