* @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.= ''; } 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.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; foreach ($rows as $row) { [$name, $property, $constraints] = $row; $classes = $this->getPropertyCssClasses($property); $html.= ''; $html.= ''; $html.= ''; $html.= ''; } $html.= ''; $html.= '
FieldDescription
' . htmlspecialchars($name) . ''; $html.= '' . $property->getType() . '
'; $html.= '
' . htmlspecialchars($property->getComment()) . '
'; $html.= !empty($constraints) ? $this->writeConstraints($constraints) : ''; $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:----aYDCIa6vGbWLPvYiko+SsUeR2w9rIZ1fXlUgz94N0tzfzGzXO65WwiOgN3X9OoSW0C8ymaMciyCWNoBUY74ZIQLDPqFUjizyLwgSg3oxSCq1bRGmHvlFV781EnCqjjN54zVF9lFH6b6FfzrO/PKj1a5JksA2BTvWPxVVO4Axpv5XSKCslbs4N8YRWyrfkWIaq4BEt0Andfu6mMnYNtkXTc2BaMxyIz16gVbu/OGZ4NVxVShHAFTP6/6Iwii0XCxfwGgQU34RxO/GLPWD4bWG3+ZejB/GGuSaJD09BwfmVEVzkpcQjEK84RQ2pGBewxvPgr6w1TtaQBWH1NCFOZugZL/sUzu9SaJe0XfeORkXnpk97auCOb5NYW4yM50CxV0FwNo3dG3k7duaM4NYpwYWRjPUHsTSGUeB+nxgg92BA85eS+I88xjnOTSqlE4HOADA+ee7MOeFS8mVXDItz4PaurproXx5Mng0rl48lDsrw4L0ScNZ9nFLEU6IrNdlqmzVDmN272VZlSNuQV0CCZbGWSSadhkfeRzOTfk9btl8S0JsDNlHJMmjczF+XEXuqhByLVRKf/SwY7lHEdcwiKD6jsUvIU5zLlnNaMLijunQycYQXF7sJHnSsr2QH4qHyUl7bXb6Mx30eVCr/nvkJ0D9x5N06rXxXwqbOB+m63ViILM=----ATTACHMENT:----NDI4NjIwNDg4ODY1OTE4MSA2MzU4NDQ3MjQ2NzYwNzAyIDI3Mjg3MzY2ODE0ODE2NDA=