Skip to content

Commit

Permalink
Render php-schema class-string values as class names instead of strin…
Browse files Browse the repository at this point in the history
…g scalars (#11)

Co-authored-by: Aleksei Gagarin <[email protected]>
Co-authored-by: kastahov <[email protected]>
  • Loading branch information
3 people authored Dec 15, 2022
1 parent a9995e0 commit 5c2b797
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/PhpFileRenderer/Exporter/Rendering/ValueRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static function render($value, bool $wrapValue = true, int $indentLevel =
return $value->toString();
case !$wrapValue || is_int($value):
return (string)$value;
case \is_string($value) && \strpos($value, '\\') !== false && \class_exists($value):
return "$value::class";
case is_string($value):
return "'" . addslashes($value) . "'";
default:
Expand Down
12 changes: 6 additions & 6 deletions tests/Schema/Renderer/Fixture/generated_schema.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

return [
'user' => [
Schema::ENTITY => 'Cycle\\Schema\\Renderer\\Tests\\Fixture\\User',
Schema::MAPPER => 'Cycle\\ORM\\Mapper\\Mapper',
Schema::ENTITY => Cycle\Schema\Renderer\Tests\Fixture\User::class,
Schema::MAPPER => Cycle\ORM\Mapper\Mapper::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'user',
Schema::PRIMARY_KEY => 'id',
Expand Down Expand Up @@ -43,8 +43,8 @@
Schema::SCHEMA => [],
],
'tag' => [
Schema::ENTITY => 'Cycle\\Schema\\Renderer\\Tests\\Fixture\\Tag',
Schema::MAPPER => 'Cycle\\ORM\\Mapper\\Mapper',
Schema::ENTITY => Cycle\Schema\Renderer\Tests\Fixture\Tag::class,
Schema::MAPPER => Cycle\ORM\Mapper\Mapper::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'tag',
Schema::PRIMARY_KEY => ['id', 'name'],
Expand All @@ -66,8 +66,8 @@
Schema::SCHEMA => [],
],
'tag_context' => [
Schema::ENTITY => 'Cycle\\Schema\\Renderer\\Tests\\Fixture\\TagContext',
Schema::MAPPER => 'Cycle\\ORM\\Mapper\\Mapper',
Schema::ENTITY => Cycle\Schema\Renderer\Tests\Fixture\TagContext::class,
Schema::MAPPER => Cycle\ORM\Mapper\Mapper::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'tag_user_map',
Schema::COLUMNS => [],
Expand Down
12 changes: 6 additions & 6 deletions tests/Schema/Renderer/Fixture/generated_schema_v2.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

return [
'user' => [
Schema::MAPPER => 'Cycle\\ORM\\Mapper\\Mapper',
Schema::MAPPER => Cycle\ORM\Mapper\Mapper::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'user',
Schema::PRIMARY_KEY => 'id',
Expand Down Expand Up @@ -40,10 +40,10 @@
],
],
],
Schema::ENTITY => 'Cycle\\Schema\\Renderer\\Tests\\Fixture\\User',
Schema::ENTITY => Cycle\Schema\Renderer\Tests\Fixture\User::class,
],
'tag' => [
Schema::MAPPER => 'Cycle\\ORM\\Mapper\\Mapper',
Schema::MAPPER => Cycle\ORM\Mapper\Mapper::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'tag',
Schema::PRIMARY_KEY => ['id', 'name'],
Expand All @@ -63,10 +63,10 @@
],
],
],
Schema::ENTITY => 'Cycle\\Schema\\Renderer\\Tests\\Fixture\\Tag',
Schema::ENTITY => Cycle\Schema\Renderer\Tests\Fixture\Tag::class,
],
'tag_context' => [
Schema::MAPPER => 'Cycle\\ORM\\Mapper\\Mapper',
Schema::MAPPER => Cycle\ORM\Mapper\Mapper::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'tag_user_map',
Schema::COLUMNS => [],
Expand All @@ -77,6 +77,6 @@
],
Schema::SCHEMA => [],
Schema::RELATIONS => [],
Schema::ENTITY => 'Cycle\\Schema\\Renderer\\Tests\\Fixture\\TagContext',
Schema::ENTITY => Cycle\Schema\Renderer\Tests\Fixture\TagContext::class,
],
];
2 changes: 1 addition & 1 deletion tests/Schema/Renderer/PhpSchemaRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function testRenderSchemaWithCustomPropertyToPhpCode(): void
return [
'Cycle\Schema\Renderer\Tests\Fixture\TagContext' => [
Schema::ROLE => 'tag_context',
Schema::MAPPER => 'Cycle\\\\ORM\\\\Mapper\\\\Mapper',
Schema::MAPPER => Cycle\ORM\Mapper\Mapper::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'tag_user_map',
Schema::COLUMNS => [],
Expand Down

0 comments on commit 5c2b797

Please sign in to comment.