-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from felixbessler/add-support-for-arrayable
Added support for Arrayable
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WendellAdriel\ValidatedDTO\Tests\Datasets; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
class ArrayableObject implements Arrayable | ||
{ | ||
public function key(): string | ||
{ | ||
return 'arrayable-object-key'; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'key' => $this->key(), | ||
]; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WendellAdriel\ValidatedDTO\Tests\Datasets; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
use WendellAdriel\ValidatedDTO\Casting\Castable; | ||
|
||
class ArrayableObjectCast implements Castable | ||
{ | ||
public function cast(string $property, mixed $value): Arrayable | ||
{ | ||
return app(ArrayableObject::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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WendellAdriel\ValidatedDTO\Tests\Datasets; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
use WendellAdriel\ValidatedDTO\Attributes\Cast; | ||
use WendellAdriel\ValidatedDTO\Attributes\Rules; | ||
use WendellAdriel\ValidatedDTO\Concerns\EmptyCasts; | ||
use WendellAdriel\ValidatedDTO\Concerns\EmptyDefaults; | ||
use WendellAdriel\ValidatedDTO\Concerns\EmptyRules; | ||
use WendellAdriel\ValidatedDTO\ValidatedDTO; | ||
|
||
class ArrayableObjectDTO extends ValidatedDTO | ||
{ | ||
use EmptyCasts, EmptyDefaults, EmptyRules; | ||
|
||
#[Rules(['required'])] | ||
#[Cast(type: ArrayableObjectCast::class)] | ||
public Arrayable $object; | ||
} |
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