{"id":18376433,"url":"https://github.com/cycle/schema-renderer","last_synced_at":"2025-07-24T07:04:24.005Z","repository":{"id":45077810,"uuid":"401633317","full_name":"cycle/schema-renderer","owner":"cycle","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-15T16:20:47.000Z","size":67,"stargazers_count":10,"open_issues_count":2,"forks_count":6,"subscribers_count":3,"default_branch":"1.x","last_synced_at":"2024-09-19T08:39:14.637Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cycle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-31T08:45:39.000Z","updated_at":"2024-06-18T15:14:23.000Z","dependencies_parsed_at":"2023-01-29T03:45:16.797Z","dependency_job_id":null,"html_url":"https://github.com/cycle/schema-renderer","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycle%2Fschema-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycle%2Fschema-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycle%2Fschema-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycle%2Fschema-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cycle","download_url":"https://codeload.github.com/cycle/schema-renderer/tar.gz/refs/heads/1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247547477,"owners_count":20956561,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-11-06T00:23:19.122Z","updated_at":"2025-07-24T07:04:23.990Z","avatar_url":"https://github.com/cycle.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cycle ORM Schema renderer\n\n[![Latest Stable Version](https://poser.pugx.org/cycle/schema-renderer/v/stable)](https://packagist.org/packages/cycle/schema-renderer)\n[![build](https://github.com/cycle/schema-renderer/actions/workflows/main.yml/badge.svg)](https://github.com/cycle/schema-renderer/actions/workflows/main.yml)\n[![static analysis](https://github.com/cycle/schema-renderer/actions/workflows/static.yml/badge.svg)](https://github.com/cycle/schema-renderer/actions/workflows/static.yml)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/cycle/schema-renderer/badges/quality-score.png?b=1.x)](https://scrutinizer-ci.com/g/cycle/schema-renderer/?branch=1.x)\n[![Codecov](https://codecov.io/gh/cycle/schema-renderer/branch/1.x/graph/badge.svg)](https://codecov.io/gh/cycle/schema-renderer/)\n\nThis package may be used to render Cycle ORM Schema in a terminal or generate php representation.\n\n## Installation\n\nThe preferred way to install this package is through [Composer](https://getcomposer.org/download/):\n\n```bash\ncomposer require cycle/schema-renderer\n```\n\n## Example\n\n### Convert schema to array\n\n```php\n$schema = new Schema([...]);\n$converter = new \\Cycle\\Schema\\Renderer\\SchemaToArrayConverter();\n\n$schemaArray = $converter-\u003econvert($schema);\n```\n\nIf passed `SchemaInterface` doesn't contain `toArray()` method then the `SchemaToArrayConverter`  will convert\nonly common properties from `Cycle\\ORM\\SchemaInterface`. Null values will be skipped also.\n\nIn this case Iif you want to use custom properties you can pass them to the constructor\n\n```php\n$converter = new \\Cycle\\Schema\\Renderer\\SchemaToArrayConverter();\n\n$schemaArray = $converter-\u003econvert($schema, [\n    42,\n    CustomClass::CUSTOM_PROPERTY,\n    ...\n]);\n```\n\n### Render schema to a terminal\n\n```php\nuse Cycle\\Schema\\Renderer\\OutputSchemaRenderer;\n\n$output = new \\Symfony\\Component\\Console\\Output\\ConsoleOutput();\n\n$renderer = new OutputSchemaRenderer(colorize: true);\n\n$output-\u003ewrite($renderer-\u003erender($schemaArray));\n```\n\nBy default, `DefaultSchemaOutputRenderer` renders in template only common properties and relations.\nCustom properties will be rendered as is in separated block.\nIf you want to extend default rendering template you can create custom renderers and add them to the Output renderer.\n\n```php\nuse Cycle\\Schema\\Renderer\\ConsoleRenderer\\Renderer;\nuse Cycle\\Schema\\Renderer\\ConsoleRenderer\\Formatter;\nuse Cycle\\Schema\\Renderer\\OutputSchemaRenderer;\n\nclass CustomPropertyRenderer implements Renderer {\n\n    public function render(Formatter $formatter, array $schema, string $role): string\n    {\n        $data = $schema['my_custom_property'] ?? null;\n\n        return \\sprintf(\n            '%s: %s',\n            $formatter-\u003etitle($this-\u003etitle),\n            $data === null ? $formatter-\u003eerror('not defined') : $formatter-\u003etypecast($data)\n        );\n    }\n}\n\n$renderer = new OutputSchemaRenderer();\n\n$renderer-\u003eaddRenderer(\n    new CustomPropertyRenderer(),\n    new PropertyRenderer('my_custom_property', 'My super property')\n);\n\n$output-\u003ewrite($renderer-\u003erender($schemaArray))\n```\n\n### Store schema in a PHP file\n\n```php\nuse Cycle\\Schema\\Renderer\\PhpSchemaRenderer;\n\n$path = __DIR__. '/schema.php'\n\n$renderer = new PhpSchemaRenderer();\n\n\\file_put_contents($path, $renderer-\u003erender($schemaArray));\n```\n\nThe Renderer generates valid PHP code, in which constants from Cycle ORM classes are substituted\nfor better readability.\n\n## License:\n\nThe MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information.\nMaintained by [Spiral Scout](https://spiralscout.com).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycle%2Fschema-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcycle%2Fschema-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycle%2Fschema-renderer/lists"}