Test case
1 generated file · +154 −0test/inputs/schema/top-level-array.schema
Aschema-phpdefault / TopLevel.php+154 −0
| @@ -0,0 +1,154 @@ | ||
| 1 | +<?php | |
| 2 | +declare(strict_types=1); | |
| 3 | + | |
| 4 | +// This is an autogenerated file:TopLevel | |
| 5 | + | |
| 6 | +class TopLevel { | |
| 7 | + private string $label; // json:label Required | |
| 8 | + private float $score; // json:score Required | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * @param string $label | |
| 12 | + * @param float $score | |
| 13 | + */ | |
| 14 | + public function __construct(string $label, float $score) { | |
| 15 | + $this->label = $label; | |
| 16 | + $this->score = $score; | |
| 17 | + } | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * @param string $value | |
| 21 | + * @throws Exception | |
| 22 | + * @return string | |
| 23 | + */ | |
| 24 | + public static function fromLabel(string $value): string { | |
| 25 | + return $value; /*string*/ | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * @throws Exception | |
| 30 | + * @return string | |
| 31 | + */ | |
| 32 | + public function toLabel(): string { | |
| 33 | + if (TopLevel::validateLabel($this->label)) { | |
| 34 | + return $this->label; /*string*/ | |
| 35 | + } | |
| 36 | + throw new Exception('never get to this TopLevel::label'); | |
| 37 | + } | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * @param string | |
| 41 | + * @return bool | |
| 42 | + * @throws Exception | |
| 43 | + */ | |
| 44 | + public static function validateLabel(string $value): bool { | |
| 45 | + return true; | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * @throws Exception | |
| 50 | + * @return string | |
| 51 | + */ | |
| 52 | + public function getLabel(): string { | |
| 53 | + if (TopLevel::validateLabel($this->label)) { | |
| 54 | + return $this->label; | |
| 55 | + } | |
| 56 | + throw new Exception('never get to getLabel TopLevel::label'); | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * @return string | |
| 61 | + */ | |
| 62 | + public static function sampleLabel(): string { | |
| 63 | + return 'TopLevel::label::31'; /*31:label*/ | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * @param float $value | |
| 68 | + * @throws Exception | |
| 69 | + * @return float | |
| 70 | + */ | |
| 71 | + public static function fromScore(float $value): float { | |
| 72 | + return $value; /*float*/ | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * @throws Exception | |
| 77 | + * @return float | |
| 78 | + */ | |
| 79 | + public function toScore(): float { | |
| 80 | + if (TopLevel::validateScore($this->score)) { | |
| 81 | + return $this->score; /*float*/ | |
| 82 | + } | |
| 83 | + throw new Exception('never get to this TopLevel::score'); | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @param float | |
| 88 | + * @return bool | |
| 89 | + * @throws Exception | |
| 90 | + */ | |
| 91 | + public static function validateScore(float $value): bool { | |
| 92 | + return true; | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * @throws Exception | |
| 97 | + * @return float | |
| 98 | + */ | |
| 99 | + public function getScore(): float { | |
| 100 | + if (TopLevel::validateScore($this->score)) { | |
| 101 | + return $this->score; | |
| 102 | + } | |
| 103 | + throw new Exception('never get to getScore TopLevel::score'); | |
| 104 | + } | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * @return float | |
| 108 | + */ | |
| 109 | + public static function sampleScore(): float { | |
| 110 | + return 32.032; /*32:score*/ | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * @throws Exception | |
| 115 | + * @return bool | |
| 116 | + */ | |
| 117 | + public function validate(): bool { | |
| 118 | + return TopLevel::validateLabel($this->label) | |
| 119 | + || TopLevel::validateScore($this->score); | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * @return stdClass | |
| 124 | + * @throws Exception | |
| 125 | + */ | |
| 126 | + public function to(): stdClass { | |
| 127 | + $out = new stdClass(); | |
| 128 | + $out->{'label'} = $this->toLabel(); | |
| 129 | + $out->{'score'} = $this->toScore(); | |
| 130 | + return $out; | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * @param stdClass $obj | |
| 135 | + * @return TopLevel | |
| 136 | + * @throws Exception | |
| 137 | + */ | |
| 138 | + public static function from(stdClass $obj): TopLevel { | |
| 139 | + return new TopLevel( | |
| 140 | + TopLevel::fromLabel($obj->{'label'}) | |
| 141 | + ,TopLevel::fromScore($obj->{'score'}) | |
| 142 | + ); | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * @return TopLevel | |
| 147 | + */ | |
| 148 | + public static function sample(): TopLevel { | |
| 149 | + return new TopLevel( | |
| 150 | + TopLevel::sampleLabel() | |
| 151 | + ,TopLevel::sampleScore() | |
| 152 | + ); | |
| 153 | + } | |
| 154 | +} |
Test case
1 generated file · +55 −0test/inputs/schema/top-level-enum.schema
Aschema-phpdefault / TopLevel.php+55 −0
| @@ -0,0 +1,55 @@ | ||
| 1 | +<?php | |
| 2 | +declare(strict_types=1); | |
| 3 | + | |
| 4 | +// This is an autogenerated file:TopLevel | |
| 5 | + | |
| 6 | +class TopLevel { | |
| 7 | + public static TopLevel $ONE; | |
| 8 | + public static TopLevel $THREE; | |
| 9 | + public static TopLevel $TWO; | |
| 10 | + public static function init() { | |
| 11 | + TopLevel::$ONE = new TopLevel('one'); | |
| 12 | + TopLevel::$THREE = new TopLevel('three'); | |
| 13 | + TopLevel::$TWO = new TopLevel('two'); | |
| 14 | + } | |
| 15 | + private string $enum; | |
| 16 | + public function __construct(string $enum) { | |
| 17 | + $this->enum = $enum; | |
| 18 | + } | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * @param TopLevel | |
| 22 | + * @return string | |
| 23 | + * @throws Exception | |
| 24 | + */ | |
| 25 | + public static function to(TopLevel $obj): string { | |
| 26 | + switch ($obj->enum) { | |
| 27 | + case TopLevel::$ONE->enum: return 'one'; | |
| 28 | + case TopLevel::$THREE->enum: return 'three'; | |
| 29 | + case TopLevel::$TWO->enum: return 'two'; | |
| 30 | + } | |
| 31 | + throw new Exception('the give value is not an enum-value.'); | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * @param mixed | |
| 36 | + * @return TopLevel | |
| 37 | + * @throws Exception | |
| 38 | + */ | |
| 39 | + public static function from($obj): TopLevel { | |
| 40 | + switch ($obj) { | |
| 41 | + case 'one': return TopLevel::$ONE; | |
| 42 | + case 'three': return TopLevel::$THREE; | |
| 43 | + case 'two': return TopLevel::$TWO; | |
| 44 | + } | |
| 45 | + throw new Exception("Cannot deserialize TopLevel"); | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * @return TopLevel | |
| 50 | + */ | |
| 51 | + public static function sample(): TopLevel { | |
| 52 | + return TopLevel::$ONE; | |
| 53 | + } | |
| 54 | +} | |
| 55 | +TopLevel::init(); |
Test case
1 generated file · +228 −0test/inputs/schema/union.schema
Aschema-phpdefault / TopLevel.php+228 −0
| @@ -0,0 +1,228 @@ | ||
| 1 | +<?php | |
| 2 | +declare(strict_types=1); | |
| 3 | + | |
| 4 | +// This is an autogenerated file:TopLevel | |
| 5 | + | |
| 6 | +class TopLevel { | |
| 7 | + private ?int $one; // json:one Optional | |
| 8 | + private bool $two; // json:two Required | |
| 9 | + private ?float $three; // json:three Optional | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * @param int|null $one | |
| 13 | + * @param bool $two | |
| 14 | + * @param float|null $three | |
| 15 | + */ | |
| 16 | + public function __construct(?int $one, bool $two, ?float $three) { | |
| 17 | + $this->one = $one; | |
| 18 | + $this->two = $two; | |
| 19 | + $this->three = $three; | |
| 20 | + } | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * @param ?int $value | |
| 24 | + * @throws Exception | |
| 25 | + * @return ?int | |
| 26 | + */ | |
| 27 | + public static function fromOne(?int $value): ?int { | |
| 28 | + if (!is_null($value)) { | |
| 29 | + return $value; /*int*/ | |
| 30 | + } else { | |
| 31 | + return null; | |
| 32 | + } | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * @throws Exception | |
| 37 | + * @return ?int | |
| 38 | + */ | |
| 39 | + public function toOne(): ?int { | |
| 40 | + if (TopLevel::validateOne($this->one)) { | |
| 41 | + if (!is_null($this->one)) { | |
| 42 | + return $this->one; /*int*/ | |
| 43 | + } else { | |
| 44 | + return null; | |
| 45 | + } | |
| 46 | + } | |
| 47 | + throw new Exception('never get to this TopLevel::one'); | |
| 48 | + } | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * @param int|null | |
| 52 | + * @return bool | |
| 53 | + * @throws Exception | |
| 54 | + */ | |
| 55 | + public static function validateOne(?int $value): bool { | |
| 56 | + if (!is_null($value)) { | |
| 57 | + } | |
| 58 | + return true; | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * @throws Exception | |
| 63 | + * @return ?int | |
| 64 | + */ | |
| 65 | + public function getOne(): ?int { | |
| 66 | + if (TopLevel::validateOne($this->one)) { | |
| 67 | + return $this->one; | |
| 68 | + } | |
| 69 | + throw new Exception('never get to getOne TopLevel::one'); | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * @return ?int | |
| 74 | + */ | |
| 75 | + public static function sampleOne(): ?int { | |
| 76 | + return 31; /*31:one*/ | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * @param bool $value | |
| 81 | + * @throws Exception | |
| 82 | + * @return bool | |
| 83 | + */ | |
| 84 | + public static function fromTwo(bool $value): bool { | |
| 85 | + return $value; /*bool*/ | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * @throws Exception | |
| 90 | + * @return bool | |
| 91 | + */ | |
| 92 | + public function toTwo(): bool { | |
| 93 | + if (TopLevel::validateTwo($this->two)) { | |
| 94 | + return $this->two; /*bool*/ | |
| 95 | + } | |
| 96 | + throw new Exception('never get to this TopLevel::two'); | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * @param bool | |
| 101 | + * @return bool | |
| 102 | + * @throws Exception | |
| 103 | + */ | |
| 104 | + public static function validateTwo(bool $value): bool { | |
| 105 | + return true; | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * @throws Exception | |
| 110 | + * @return bool | |
| 111 | + */ | |
| 112 | + public function getTwo(): bool { | |
| 113 | + if (TopLevel::validateTwo($this->two)) { | |
| 114 | + return $this->two; | |
| 115 | + } | |
| 116 | + throw new Exception('never get to getTwo TopLevel::two'); | |
| 117 | + } | |
| 118 | + | |
| 119 | + /** | |
| 120 | + * @return bool | |
| 121 | + */ | |
| 122 | + public static function sampleTwo(): bool { | |
| 123 | + return true; /*32:two*/ | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * @param ?float $value | |
| 128 | + * @throws Exception | |
| 129 | + * @return ?float | |
| 130 | + */ | |
| 131 | + public static function fromThree(?float $value): ?float { | |
| 132 | + if (!is_null($value)) { | |
| 133 | + return $value; /*float*/ | |
| 134 | + } else { | |
| 135 | + return null; | |
| 136 | + } | |
| 137 | + } | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * @throws Exception | |
| 141 | + * @return ?float | |
| 142 | + */ | |
| 143 | + public function toThree(): ?float { | |
| 144 | + if (TopLevel::validateThree($this->three)) { | |
| 145 | + if (!is_null($this->three)) { | |
| 146 | + return $this->three; /*float*/ | |
| 147 | + } else { | |
| 148 | + return null; | |
| 149 | + } | |
| 150 | + } | |
| 151 | + throw new Exception('never get to this TopLevel::three'); | |
| 152 | + } | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * @param float|null | |
| 156 | + * @return bool | |
| 157 | + * @throws Exception | |
| 158 | + */ | |
| 159 | + public static function validateThree(?float $value): bool { | |
| 160 | + if (!is_null($value)) { | |
| 161 | + } | |
| 162 | + return true; | |
| 163 | + } | |
| 164 | + | |
| 165 | + /** | |
| 166 | + * @throws Exception | |
| 167 | + * @return ?float | |
| 168 | + */ | |
| 169 | + public function getThree(): ?float { | |
| 170 | + if (TopLevel::validateThree($this->three)) { | |
| 171 | + return $this->three; | |
| 172 | + } | |
| 173 | + throw new Exception('never get to getThree TopLevel::three'); | |
| 174 | + } | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * @return ?float | |
| 178 | + */ | |
| 179 | + public static function sampleThree(): ?float { | |
| 180 | + return 33.033; /*33:three*/ | |
| 181 | + } | |
| 182 | + | |
| 183 | + /** | |
| 184 | + * @throws Exception | |
| 185 | + * @return bool | |
| 186 | + */ | |
| 187 | + public function validate(): bool { | |
| 188 | + return TopLevel::validateOne($this->one) | |
| 189 | + || TopLevel::validateTwo($this->two) | |
| 190 | + || TopLevel::validateThree($this->three); | |
| 191 | + } | |
| 192 | + | |
| 193 | + /** | |
| 194 | + * @return stdClass | |
| 195 | + * @throws Exception | |
| 196 | + */ | |
| 197 | + public function to(): stdClass { | |
| 198 | + $out = new stdClass(); | |
| 199 | + $out->{'one'} = $this->toOne(); | |
| 200 | + $out->{'two'} = $this->toTwo(); | |
| 201 | + $out->{'three'} = $this->toThree(); | |
| 202 | + return $out; | |
| 203 | + } | |
| 204 | + | |
| 205 | + /** | |
| 206 | + * @param stdClass $obj | |
| 207 | + * @return TopLevel | |
| 208 | + * @throws Exception | |
| 209 | + */ | |
| 210 | + public static function from(stdClass $obj): TopLevel { | |
| 211 | + return new TopLevel( | |
| 212 | + TopLevel::fromOne($obj->{'one'}) | |
| 213 | + ,TopLevel::fromTwo($obj->{'two'}) | |
| 214 | + ,TopLevel::fromThree($obj->{'three'}) | |
| 215 | + ); | |
| 216 | + } | |
| 217 | + | |
| 218 | + /** | |
| 219 | + * @return TopLevel | |
| 220 | + */ | |
| 221 | + public static function sample(): TopLevel { | |
| 222 | + return new TopLevel( | |
| 223 | + TopLevel::sampleOne() | |
| 224 | + ,TopLevel::sampleTwo() | |
| 225 | + ,TopLevel::sampleThree() | |
| 226 | + ); | |
| 227 | + } | |
| 228 | +} |
No generated files match these filters.