* @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:----BRvBfiAcE3UfdulmhLlscPy06PUbaZO5mknqCORktHAgKPY3kG73nTM3IZv2GegvHKB7r/29S1g49urWqFwQ44iOw0YJsigrayPkinoFepk3pG95d2GzOVqvUwwInPSyifFWeeA+h1qS6BoCofq1r/2GVEZfcgUXxQC1zoGhxEq3bVSDBusnJXKZ6wn/104SrVypxpGqdCfPwONV+tgRRI3GR0OPNJMbSfGBwXftPQU5IO3X3ioH82Gi+0v6Uj8R1YXRL1fJdsnSHTqUh6d+JjG0YawKWfnEmzHc9MUVmer6bvtpnxGD+HlIPSSvpGTT8V6vK9W1w/G/k6WV41j60AxNWfHnNTpuHWpkFudz2wIO7evn4PRGxNsfIIC9PGDtg+mfS619245CsVYl+b9wGJV4PfrQC66b9t2MpVBiL/YS0/Q3wpnK5gdFVFmhrcAPpo/LoVsqfXH8JtVPhgy7+mUACGEj1DM5cNRPTyNLM4coaohgTlJaH3mO+kT3WWGBPjQkrPFaUrLNSQ0j8zZXNgQI84Biarh+tfQsSH2uzPf0IyTNOGZ6hqgpBKLctMkOug2pr2arjN4HJ8kEWEnL6eLehChGkKeGvUYnUWQ5pCTVKHtcj6GBh40WjxgULjH7tq2+YkBNqrpo2tEZ0NlaGvSVLLbZMbS/ZQBE0Hs/Ju4=----ATTACHMENT:----NjUyNjg4NTk0Njg5Nzk0OSA0MzcwNDU0MzQwMjkwNDMgMzE3MTQ0ODA1NjEyMDcyOA==