-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRule.php
56 lines (47 loc) · 1.07 KB
/
Rule.php
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
54
55
56
<?php
declare(strict_types=1);
namespace F9Web\ValidationRules;
use Illuminate\Contracts\Validation\Rule as BaseRule;
use Illuminate\Support\Str;
use function __;
use function class_basename;
use function get_called_class;
abstract class Rule implements BaseRule
{
/** @var string */
protected $attribute;
/**
* @return string
*/
public function message(): string
{
return __(
'f9web-validation-rules::messages.'.$this->getMessageKey(),
[
'attribute' => $this->getAttribute(),
]
);
}
/**
* @return string
*/
public function getAttribute(): string
{
return $this->attribute;
}
/**
* @param string $attribute
*/
public function setAttribute(string $attribute): void
{
$this->attribute = $attribute;
}
/**
* @return string
*/
public function getMessageKey(): string
{
$calledClassName = class_basename(get_called_class());
return Str::slug(Str::snake($calledClassName));
}
}