1 | <?php |
||
13 | abstract class AbstractType extends \SwaggerGen\Swagger\AbstractObject |
||
14 | { |
||
15 | |||
16 | const REGEX_START = '/^'; |
||
17 | const REGEX_FORMAT = '([a-z][a-z0-9]*)'; |
||
18 | const REGEX_CONTENT = '(?:\((.*)\))?'; |
||
19 | const REGEX_RANGE = '(?:([[<])(\\d*),(\\d*)([\\]>]))?'; |
||
20 | const REGEX_DEFAULT = '(?:=(.+))?'; |
||
21 | const REGEX_END = '$/i'; |
||
22 | |||
23 | private static $classTypes = array( |
||
24 | 'integer' => 'Integer', |
||
25 | 'int' => 'Integer', |
||
26 | 'int32' => 'Integer', |
||
27 | 'int64' => 'Integer', |
||
28 | 'long' => 'Integer', |
||
29 | 'float' => 'Number', |
||
30 | 'double' => 'Number', |
||
31 | 'string' => 'String', |
||
32 | 'uuid' => 'StringUuid', |
||
33 | 'byte' => 'String', |
||
34 | 'binary' => 'String', |
||
35 | 'password' => 'String', |
||
36 | 'enum' => 'String', |
||
37 | 'boolean' => 'Boolean', |
||
38 | 'bool' => 'Boolean', |
||
39 | 'array' => 'Array', |
||
40 | 'csv' => 'Array', |
||
41 | 'ssv' => 'Array', |
||
42 | 'tsv' => 'Array', |
||
43 | 'pipes' => 'Array', |
||
44 | 'date' => 'Date', |
||
45 | 'datetime' => 'Date', |
||
46 | 'date-time' => 'Date', |
||
47 | 'object' => 'Object', |
||
48 | 'refobject' => 'ReferenceObject', |
||
49 | 'allof' => 'AllOf', |
||
50 | ); |
||
51 | |||
52 | private $example = null; |
||
53 | |||
54 | /** |
||
55 | * Swap values of two variables. |
||
56 | * Used for sorting. |
||
57 | * @param mixed $a |
||
58 | * @param mixed $b |
||
59 | */ |
||
60 | protected static function swap(&$a, &$b) |
||
61 | { |
||
62 | $tmp = $a; |
||
63 | $a = $b; |
||
64 | $b = $tmp; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @param string $list |
||
69 | * @return array |
||
70 | */ |
||
71 | protected static function parseList($list) |
||
72 | { |
||
73 | $ret = array(); |
||
74 | while ($item = self::parseListItem($list)) { |
||
75 | $ret[] = $item; |
||
76 | } |
||
77 | return $ret; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Extract an item from a comma-separated list of items. |
||
82 | * |
||
83 | * i.e. `a(x(x,x)),b(x)` returns `a(x(x,x))` and changes `$list` into `b(x)`. |
||
84 | * Note: brace nesting is not checked, e.g. `a{b(})` is a valid list item. |
||
85 | * |
||
86 | * @param string $list the list to parse |
||
87 | * @return string the extracted item |
||
88 | */ |
||
89 | protected static function parseListItem(&$list) |
||
90 | { |
||
91 | $item = ''; |
||
92 | |||
93 | $depth = 0; |
||
94 | $index = 0; |
||
95 | while ($index < strlen($list)) { |
||
96 | $c = $list{$index++}; |
||
97 | |||
98 | if (strpos('{([<', $c) !== false) { |
||
99 | ++$depth; |
||
100 | } elseif (strpos('})]>', $c) !== false) { |
||
101 | --$depth; |
||
102 | } elseif ($c === ',' && $depth === 0) { |
||
103 | break; |
||
104 | } |
||
105 | |||
106 | $item .= $c; |
||
107 | } |
||
108 | $list = substr($list, $index); |
||
109 | |||
110 | return $item; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @var string $definition |
||
115 | */ |
||
116 | public function __construct(\SwaggerGen\Swagger\AbstractObject $parent, $definition) |
||
117 | { |
||
118 | parent::__construct($parent); |
||
119 | |||
120 | $this->parseDefinition($definition); |
||
121 | } |
||
122 | |||
123 | abstract protected function parseDefinition($definition); |
||
124 | |||
125 | /** |
||
126 | * Overwrites default AbstractObject parser, since Types should not handle |
||
127 | * extensions themselves. |
||
128 | * |
||
129 | * @param string $command |
||
130 | * @param string $data |
||
131 | * @return \SwaggerGen\Swagger\Type\AbstractType|boolean |
||
132 | */ |
||
133 | public function handleCommand($command, $data = null) |
||
161 | |||
162 | public function toArray() |
||
168 | |||
169 | /** |
||
170 | * @param \SwaggerGen\Swagger\AbstractObject $parent |
||
171 | * @param string $definition |
||
172 | * @param string $error |
||
173 | * @return self |
||
174 | */ |
||
175 | public static function typeFactory($parent, $definition, $error = "Unparseable schema type definition: '%s'") |
||
201 | |||
202 | } |
||
203 |