-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recursive attribute handling and object casting
- Loading branch information
Showing
19 changed files
with
247 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Database\Casters; | ||
|
||
use Tempest\Mapper\Caster; | ||
|
||
final class RelationCaster implements Caster | ||
{ | ||
public function cast(mixed $input): mixed | ||
{ | ||
return $input; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Mapper\Casters; | ||
|
||
use Tempest\Mapper\Caster; | ||
use Tempest\Reflection\TypeReflector; | ||
use Throwable; | ||
|
||
final readonly class ObjectCaster implements Caster | ||
{ | ||
public function __construct( | ||
private TypeReflector $type, | ||
) { | ||
} | ||
|
||
public function cast(mixed $input): mixed | ||
{ | ||
try { | ||
return $this->type->asClass()->newInstanceArgs([$input]); | ||
} catch (Throwable) { | ||
return $input; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Tempest/Reflection/tests/Fixtures/ChildWithRecursiveAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Reflection\Tests\Fixtures; | ||
|
||
class ChildWithRecursiveAttribute extends ParentWithRecursiveAttribute | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Tempest/Reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Reflection\Tests\Fixtures; | ||
|
||
class ClassWithInterfaceWithRecursiveAttribute implements InterfaceWithRecursiveAttribute | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Tempest/Reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Reflection\Tests\Fixtures; | ||
|
||
#[RecursiveAttribute] | ||
interface InterfaceWithRecursiveAttribute | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Tempest/Reflection/tests/Fixtures/ParentWithRecursiveAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Reflection\Tests\Fixtures; | ||
|
||
#[RecursiveAttribute] | ||
abstract class ParentWithRecursiveAttribute | ||
{ | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Tempest/Reflection/tests/Fixtures/RecursiveAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Reflection\Tests\Fixtures; | ||
|
||
use Attribute; | ||
|
||
#[Attribute] | ||
final class RecursiveAttribute | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/Integration/ORM/Migrations/CreateCarbonModelTable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Tempest\Integration\ORM\Migrations; | ||
|
||
use Tempest\Database\DatabaseMigration; | ||
use Tempest\Database\QueryStatement; | ||
use Tempest\Database\QueryStatements\CreateTableStatement; | ||
use Tempest\Database\QueryStatements\DropTableStatement; | ||
use Tests\Tempest\Integration\ORM\Models\CarbonModel; | ||
|
||
final class CreateCarbonModelTable implements DatabaseMigration | ||
{ | ||
public string $name = '2024-12-17_create_users_table'; | ||
|
||
public function up(): QueryStatement | ||
{ | ||
return CreateTableStatement::forModel(CarbonModel::class) | ||
->primary() | ||
->raw('`createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP'); | ||
} | ||
|
||
public function down(): QueryStatement | ||
{ | ||
return DropTableStatement::forModel(CarbonModel::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Tempest\Integration\ORM\Models; | ||
|
||
use Carbon\Carbon; | ||
use Tempest\Database\DatabaseModel; | ||
use Tempest\Database\IsDatabaseModel; | ||
|
||
final class CarbonModel implements DatabaseModel | ||
{ | ||
use IsDatabaseModel; | ||
|
||
public function __construct( | ||
public Carbon $createdAt, | ||
) { | ||
} | ||
} |