namespace Tests\Fixtures\Nested;
use DragonCode\SimpleDataTransferObject\DataTransferObject;
class Company extends DataTransferObject
{
public string $title;
/** @var \Tests\Fixtures\Nested\Project[] */
public array $projects;
protected function castProjects(array $projects): array
{
return array_map(static function (array $project) {
return Project::make($project);
}, $projects);
}
}
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
use Tests\Fixtures\Simple;
class Foo
{
protected array $items = [
'foo' => 'Foo',
'bar' => 'Bar',
];
protected function dto(): DataTransferObject
{
return Simple::fromArray($this->items);
}
}
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
use Tests\Fixtures\Simple;
class Foo
{
protected string $json = '{"foo":"Foo","bar":"Bar"}';
protected function dto(): DataTransferObject
{
return Simple::fromJson($this->json);
}
}
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
use Tests\Fixtures\CustomObject;
use Tests\Fixtures\Simple;
class Foo
{
protected CustomObject $object;
protected function dto(): DataTransferObject
{
return Simple::fromObject($this->object);
}
}
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
use Symfony\Component\HttpFoundation\Request;
use Tests\Fixtures\Simple;
class Foo
{
protected Request $request;
protected function dto(): DataTransferObject
{
return Simple::fromRequest($this->request)
}
}
namespace App\Http\Requests\Companies;
use App\Objects\Company;
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
use DragonCode\Contracts\DataTransferObject\Dtoable;
class CreateRequest implements Dtoable
{
// ...
public function dto(): DataTransferObject
{
return Company::fromRequest($this);
}
}
// Other place
public function store(CreateRequest $request)
{
$name = $request->dto()->name;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.