diff --git a/src/PhpFileRenderer/Exporter/Rendering/ValueRenderer.php b/src/PhpFileRenderer/Exporter/Rendering/ValueRenderer.php index 466cd89..529a2f7 100644 --- a/src/PhpFileRenderer/Exporter/Rendering/ValueRenderer.php +++ b/src/PhpFileRenderer/Exporter/Rendering/ValueRenderer.php @@ -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: diff --git a/tests/Schema/Renderer/Fixture/generated_schema.stub.php b/tests/Schema/Renderer/Fixture/generated_schema.stub.php index 208186f..082d838 100644 --- a/tests/Schema/Renderer/Fixture/generated_schema.stub.php +++ b/tests/Schema/Renderer/Fixture/generated_schema.stub.php @@ -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', @@ -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'], @@ -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 => [], diff --git a/tests/Schema/Renderer/Fixture/generated_schema_v2.stub.php b/tests/Schema/Renderer/Fixture/generated_schema_v2.stub.php index 5321ef4..c488978 100644 --- a/tests/Schema/Renderer/Fixture/generated_schema_v2.stub.php +++ b/tests/Schema/Renderer/Fixture/generated_schema_v2.stub.php @@ -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', @@ -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'], @@ -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 => [], @@ -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, ], ]; diff --git a/tests/Schema/Renderer/PhpSchemaRendererTest.php b/tests/Schema/Renderer/PhpSchemaRendererTest.php index 7872870..acce5e4 100644 --- a/tests/Schema/Renderer/PhpSchemaRendererTest.php +++ b/tests/Schema/Renderer/PhpSchemaRendererTest.php @@ -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 => [],