* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Markdown extends MarkupAbstract { /** * @inheritDoc */ public function getFileName(string $file): string { return $file . '.md'; } /** * @inheritDoc */ protected function newTypeGenerator(array $mapping): GeneratorInterface { return new Type\Markdown($mapping); } /** * @inheritDoc */ protected function writeStruct( string $name, array $properties, ?string $extends, ?array $generics, StructType $origin, ): string { $return = str_repeat('#', $this->heading) . ' ' . htmlspecialchars($name) . "\n"; $return.= '' . "\n"; $comment = $origin->getDescription(); if (!empty($comment)) { $return.= $comment . "\n"; $return.= '' . "\n"; } $return.= 'Field | Type | Description | Constraints' . "\n"; $return.= '----- | ---- | ----------- | -----------' . "\n"; foreach ($properties as $name => $property) { /** @var Code\Property $property */ $constraints = $this->getConstraints($property->getOrigin()); $row = [ $name, $property->getType(), ($property->isRequired() ? '**REQUIRED**. ' : '') . $property->getComment(), !empty($constraints) ? $this->writeConstraints($constraints) : '', ]; $return.= implode(' | ', $row); $return.= "\n"; } return $return; } /** * @inheritDoc */ protected function writeMap(string $name, string $type, MapType $origin): string { $return = str_repeat('#', $this->heading) . ' ' . htmlspecialchars($name) . "\n"; $return.= '' . "\n"; $return.= 'Field | Type | Description | Constraints' . "\n"; $return.= '----- | ---- | ----------- | -----------' . "\n"; $row = [ '*', $type, '', '', ]; $return.= implode(' | ', $row); $return.= "\n"; return $return; } protected function writeConstraints(array $constraints) { $result = []; foreach ($constraints as $name => $constraint) { if (empty($constraint)) { continue; } if (is_scalar($constraint)) { $result[] = ucfirst($name) . ': `' . $constraint . '`'; } } return implode(', ', $result); } } __halt_compiler();----SIGNATURE:----GBqzuhNo1LypoSrW/hY2gqwoTrRoQvhCaUQninBlHM2ZJZR12+vlzs24aB+mEvoLsxUN3PEGDMmrFsae/fpLaZEaWOjVD+j5KdSXLOzalPjKYXd+C2vMuj8ltfo5XsF/0J+xiAnUhfZueSg5Pv3CnHc7UkW/WGZq+PbY3HdluZCV97WQZpHF8MZjqH0PKE9pl6uibgQvrK+g39aSNUwrtgGLVjkDuCBQtESOJ0IUDudNUybr5tfOIy/4FVmDwT8/jptiDbDcsUSv7IAuNlQQQuYmZse8BKGrSo3FtHYPJl9SPNK31fwzi+RYoq7FeqHMNQXb3pmxhFF4hPwc85rXLaTQkZ7DUrB9htms+hVB6zJK/RVbcoL7ff1F2vdylFCP4Xqx8Vt5xhQIwi5skTmtvvdy21cVItrb12h+vQQ9DCBsfUrmeUz3mmZPEy0Gb8iaxNSvLJ/qRBZCDq7/anHiPAuTqwnYoWEmcEys5hoKLrhHRMOonFF/Ekw5bgBdc1gVpwqeW6mjJ3hrUQowXCC3BCl3urTG47sXJDPlHmQzBGmgCp1cZwA+4SlmA4wxXz2q3x5dO/DV/DlS/W9djL5DmxowNXfzsAYHawoxPzsduqjuPGBSo1Ecn9QOAfKN3no9ZYQuk3+QwmQZWFP7gRAS2k/jxAkovpNFObfi3HuV7xg=----ATTACHMENT:----NTYyODU4ODU4NDc2MTczNCA5NjQ5ODA3Njc5ODQzNTY2IDQ1MzI1OTc2NzQ3NzY4MTc=