* @license http://www.apache.org/licenses/LICENSE-2.0
* @link http://phpsx.org
*/
class Html extends MarkupAbstract
{
/**
* @inheritDoc
*/
public function getFileName(string $file): string
{
return $file . '.html';
}
/**
* @inheritDoc
*/
protected function newTypeGenerator(array $mapping): GeneratorInterface
{
return new Type\Html($mapping);
}
/**
* @inheritDoc
*/
protected function writeStruct(
string $name,
array $properties,
?string $extends,
?array $generics,
StructType $origin,
): string {
$title = '' . htmlspecialchars($name) . '';
if (!empty($generics)) {
$title.= '<' . implode(', ', $generics) . '>';
}
if (!empty($extends)) {
$title.= ' extends ' . htmlspecialchars($extends) . '';
}
$return = '
';
$return.= '
heading . '>' . $title . 'heading . '>';
$comment = $origin->getDescription();
if (!empty($comment)) {
$return.= '
' . htmlspecialchars($comment) . '
';
}
$rows = [];
foreach ($properties as $name => $property) {
/** @var Code\Property $property */
$rows[] = [
$name,
$property,
$this->getConstraints($property->getOrigin()),
];
}
$return.= $this->generateJson($rows);
$return.= $this->generateTable($rows);
$return.= '
';
return $return . "\n";
}
/**
* @inheritDoc
*/
protected function writeMap(string $name, string $type, MapType $origin): string
{
$return = '';
$return.= '
heading . '>' . $name . 'heading . '>';
$comment = $origin->getDescription();
if (!empty($comment)) {
$return.= '
' . htmlspecialchars($comment) . '
';
}
$return.= '
' . $type . '
';
$return.= '
';
return $return . "\n";
}
protected function writeArray(string $name, string $type, ArrayType $origin): string
{
$return = '';
$return.= '
heading . '>' . $name . 'heading . '>';
$comment = $origin->getDescription();
if (!empty($comment)) {
$return.= '
' . htmlspecialchars($comment) . '
';
}
$return.= '
' . $type . '
';
$return.= '
';
return $return . "\n";
}
protected function writeUnion(string $name, string $type, UnionType $origin): string
{
$return = '';
$return.= '
heading . '>' . $name . 'heading . '>';
$comment = $origin->getDescription();
if (!empty($comment)) {
$return.= '
' . htmlspecialchars($comment) . '
';
}
$return.= '
OneOf: ' . $type . '
';
$return.= '
';
return $return . "\n";
}
protected function writeIntersection(string $name, string $type, IntersectionType $origin): string
{
$return = '';
$return.= '
heading . '>' . $name . 'heading . '>';
$comment = $origin->getDescription();
if (!empty($comment)) {
$return.= '
' . htmlspecialchars($comment) . '
';
}
$return.= '
AllOf: ' . $type . '
';
$return.= '
';
return $return . "\n";
}
protected function writeReference(string $name, string $type, ReferenceType $origin): string
{
$generics = '';
$template = $origin->getTemplate();
if (!empty($template)) {
foreach ($template as $key => $value) {
$generics.= "\n";
$generics.= '"' . htmlspecialchars($key) . '"';
$generics.= ' = ';
$generics.= '' . $value . '';
}
}
$return = '';
$return.= '
heading . '>' . $name . 'heading . '>';
$comment = $origin->getDescription();
if (!empty($comment)) {
$return.= '
' . htmlspecialchars($comment) . '
';
}
$return.= '
';
$return.= 'Reference: ' . $type;
$return.= $generics;
$return.= '';
$return.= '
';
return $return . "\n";
}
/**
* @param array $constraints
* @return string
*/
protected function writeConstraints(array $constraints): string
{
$html = '';
foreach ($constraints as $name => $constraint) {
if (empty($constraint)) {
continue;
}
$html.= '- ' . htmlspecialchars(ucfirst($name)) . '
';
$html.= '- ';
$type = strtolower($name);
if ($name == 'enum') {
$html.= '
';
foreach ($constraint as $prop) {
$html.= '' . htmlspecialchars(json_encode($prop)) . ' ';
}
$html.= '
';
} elseif ($name == 'const') {
$html.= '';
$html.= '' . htmlspecialchars(json_encode($constraint)) . '';
$html.= '';
} else {
$html.= '' . htmlspecialchars($constraint) . '';
}
$html.= ' ';
}
$html.= '
';
return $html;
}
private function generateTable(array $rows): string
{
$html = '';
$html.= '';
$html.= '';
$html.= '';
$html.= '';
$html.= '';
$html.= '';
$html.= '| Field | ';
$html.= 'Description | ';
$html.= '
';
$html.= '';
$html.= '';
foreach ($rows as $row) {
[$name, $property, $constraints] = $row;
$classes = $this->getPropertyCssClasses($property);
$html.= '';
$html.= '| ' . htmlspecialchars($name) . ' | ';
$html.= '';
$html.= '' . $property->getType() . ' ';
$html.= '' . htmlspecialchars($property->getComment()) . ' ';
$html.= !empty($constraints) ? $this->writeConstraints($constraints) : '';
$html.= ' | ';
$html.= '
';
}
$html.= '';
$html.= '
';
return $html;
}
private function generateJson(array $rows): string
{
$html = '{' . "\n";
foreach ($rows as $row) {
[$name, $property] = $row;
$html.= ' ';
$html.= '"' . htmlspecialchars($name) . '"';
$html.= ': ';
$html.= '' . $property->getType() . '';
$html.= ',';
$html.= "\n";
}
$html.= '}';
return '' . $html . '
';
}
private function getPropertyCssClasses(Code\Property $property): array
{
$classes = [];
$classes[] = $property->isRequired() ? 'psx-property-required' : 'psx-property-optional';
if ($property->isDeprecated()) {
$classes[] = 'psx-property-deprecated';
}
if ($property->isNullable()) {
$classes[] = 'psx-property-nullable';
}
if ($property->isReadonly()) {
$classes[] = 'psx-property-readonly';
}
return $classes;
}
}
__halt_compiler();----SIGNATURE:----nczk9RLtzLGVX7ojFXyJCT5KH5Vc701G2OLikBA3NudnSmZSbZzTXb+5+nqLeUPGPgA7aX0T2sMz5qxoo5nsdp+Xo/6xX8uOe3r2yBDsTij55rP4Iv3BrHUaED5uEnKbuY/a0wymaZMVruDe1Cb1ovJshDVltGB9XCj/omvgqLUvJgaOdkiDHUzx42sen03UDfokOu0uDLDzdD4U6rma+VIpjcW5uagWrMzS0cgxQm0Ivv1SuEt+IemUD6t9U4tlHlynI/pNbu2lxAbuWvxWCY/9yAzMOdyjE4S8sTWkZefwECjB8z11Ka5pARoCsibJhJUdgUFvx1ZUs4KpcYtgBeDYpEhx1RYPnngYqqke5pvFfSzUzmVW9VP+re67i8Gk/lTP0NnjJ69qWtuSRFaev6sv6XEipd5adv1QdZ0mK0wtFB/bmUKDUrUg0pRSlw/gIDgcnRthFx2pK4R7NKUMk05f5H2iL42LV1lX1zZRYQmp38HEV8O1ekule0R40ySOzTBbbWUov05I1ku77OQWoaEBDRGx8097vXSHcodktAz3MiILIEFacLUdxUrX4XoQYua6AMYBllYiEUxJV+ml9eqYdwyMOSe55U8O95knRGW84o7DpZ2qOSORPABJRKYauf3oO7IELQ8WxlpWTNFr3mIWsXy8rckJIbbOJsZhuQk=----ATTACHMENT:----NTYxOTEzMTUwMTgzMjc4OCAzODY4MTg2NjAxODIyMTU4IDYzODkwNzkzMjMxNjMxNjQ=