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 a primitive PHP type
33 * @param string $typehint
36 protected function toPrimitiveType($typehint)
38 if (str_ends_with($typehint, '[]')) {
42 if (in_array($typehint, ['boolean', 'false', 'true'])) {
46 if (in_array($typehint, ['integer', 'date'])) {
50 if ($typehint === 'file') {
54 // fully qualified class name
55 if ($typehint[0] === '\\') {
56 return ltrim($typehint, '\\');
59 // relative class name, try to resolve
60 if ($this->context
&& ctype_upper($typehint[0])) {
61 return ClassResolver
::getInstance()->resolve($typehint, $this->context
);
68 * Return a primitive type understood by the XMLRPC server
70 * @param string $typehint
73 public function getJSONRPCType()
75 return $this->toPrimitiveType($this->typehint
);
79 * If this is an array, return the type of the array elements
81 * @return Type|null null if this is not a typed array
83 public function getSubType()
85 $type = $this->typehint
;
86 if (!str_ends_with($type, '[]')) {
89 $type = substr($type, 0, -2);
90 return new Type($type, $this->context
);
94 * Return a type understood by the XMLRPC server
98 public function getXMLRPCType()
100 $type = $this->typehint
;
103 if (in_array($type, ['date', 'file', 'struct'])) {
107 $type = $this->toPrimitiveType($this->typehint
);
110 if (in_array($type, ['int', 'string', 'double', 'bool', 'array'])) {
114 // everything else is an object
115 return 'object'; //should this return 'struct'?