| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\DTO;
- use App\Http\Requests\PermissionRequest;
- readonly class PermissionDTO
- {
- public function __construct(
- public string $scope,
- public string $description,
- public string $bits,
- public ?string $parent_id,
- ) {
- }
- public static function fromRequest(PermissionRequest $request): self
- {
- return new self(
- scope: $request->validated(key: 'scope'),
- description: $request->validated(key: 'description'),
- bits: $request->validated(key: 'bits'),
- parent_id: $request->validated(key: 'parent_id'),
- );
- }
- public static function fromArray(array $data): self
- {
- return new self(
- scope: $data['scope'],
- description: $data['description'],
- bits: $data['bits'],
- parent_id: isset($data['parent_id']) ? $data['parent_id'] : null,
- );
- }
- public function toArray(): array
- {
- return [
- 'scope' => $this->scope,
- 'description' => $this->description,
- 'bits' => $this->bits,
- 'parent_id' => $this->parent_id,
- ];
- }
- }
|