This repository was archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.php
More file actions
53 lines (47 loc) · 1.39 KB
/
Copy pathData.php
File metadata and controls
53 lines (47 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Kellton\Tools\Features\Data;
use Kellton\Tools\Features\Data\Exceptions\MissingConstructor;
use Kellton\Tools\Features\Data\Exceptions\WrongDefaultValue;
use Kellton\Tools\Features\Data\Services\DataService;
use Kellton\Tools\Features\Data\Services\RuleService;
use Illuminate\Validation\ValidationException;
use ReflectionException;
/**
* Class Data is the base class for all data classes.
*/
readonly abstract class Data
{
/**
* Crate data instance from a multiple sources.
*
* @param mixed ...$payloads
*
* @return static
*
* @throws WrongDefaultValue
* @throws MissingConstructor
* @throws ReflectionException
* @throws ValidationException
*/
public static function create(mixed ...$payloads): static
{
/** @var DataService $service */
$service = app(DataService::class);
return $service->create(static::class, ...$payloads);
}
/**
* Returns the validation rules.
* This should be mainly used only for testing.
*
* @return array
*
* @throws MissingConstructor
* @throws ReflectionException
*/
public static function getValidationRules(): array
{
/** @var RuleService $service */
$service = app(RuleService::class);
return $service->getByClass(static::class)->transform(fn ($value) => $value->get('rules'))->toArray();
}
}