Utils for Cycle ORM Schema rendering

1.2.0 2022-12-15 16:14 UTC

This package is auto-updated.

Last update: 2024-06-15 19:47:28 UTC


Cycle ORM Schema renderer

Latest Stable Version build static analysis Scrutinizer Code Quality Codecov StyleCI

This package may be used to render Cycle ORM Schema in a terminal or generate php representation.


The preferred way to install this package is through Composer:

composer require cycle/schema-renderer


Convert schema to array

$schema = new Schema([...]);
$converter = new \Cycle\Schema\Renderer\SchemaToArrayConverter();

$schemaArray = $converter->convert($schema);

If passed SchemaInterface doesn't contain toArray() method then the SchemaToArrayConverter will convert only common properties from Cycle\ORM\SchemaInterface. Null values will be skipped also.

In this case Iif you want to use custom properties you can pass them to the constructor

$converter = new \Cycle\Schema\Renderer\SchemaToArrayConverter();

$schemaArray = $converter->convert($schema, [

Render schema to a terminal

use Cycle\Schema\Renderer\OutputSchemaRenderer;

$output = new \Symfony\Component\Console\Output\ConsoleOutput();

$renderer = new OutputSchemaRenderer(colorize: true);


By default, DefaultSchemaOutputRenderer renders in template only common properties and relations. Custom properties will be rendered as is in separated block. If you want to extend default rendering template you can create custom renderers and add them to the Output renderer.

use Cycle\Schema\Renderer\ConsoleRenderer\Renderer;
use Cycle\Schema\Renderer\ConsoleRenderer\Formatter;
use Cycle\Schema\Renderer\OutputSchemaRenderer;

class CustomPropertyRenderer implements Renderer {

    public function render(Formatter $formatter, array $schema, string $role): string
        $data = $schema['my_custom_property'] ?? null;

        return \sprintf(
            '%s: %s',
            $data === null ? $formatter->error('not defined') : $formatter->typecast($data)

$renderer = new OutputSchemaRenderer();

    new CustomPropertyRenderer(),
    new PropertyRenderer('my_custom_property', 'My super property')


Store schema in a PHP file

use Cycle\Schema\Renderer\PhpSchemaRenderer;

$path = __DIR__. '/schema.php'

$renderer = new PhpSchemaRenderer();

\file_put_contents($path, $renderer->render($schemaArray));

The Renderer generates valid PHP code, in which constants from Cycle ORM classes are substituted for better readability.


The MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.