9
9
10
10
namespace Flarum \Foundation ;
11
11
12
+ use Illuminate \Contracts \Cache \Store as Cache ;
12
13
use Illuminate \Support \Arr ;
13
14
use Illuminate \Validation \Factory ;
14
15
use Illuminate \Validation \ValidationException ;
@@ -18,6 +19,8 @@ abstract class AbstractValidator
18
19
{
19
20
use ExtensionIdTrait;
20
21
22
+ public static string $ CORE_VALIDATION_CACHE_KEY = 'core.validation.extension_id_class_names ' ;
23
+
21
24
/**
22
25
* @var array
23
26
*/
@@ -43,14 +46,20 @@ public function addConfiguration($callable)
43
46
*/
44
47
protected $ translator ;
45
48
49
+ /**
50
+ * @var Cache
51
+ */
52
+ protected $ cache ;
53
+
46
54
/**
47
55
* @param Factory $validator
48
56
* @param TranslatorInterface $translator
49
57
*/
50
- public function __construct (Factory $ validator , TranslatorInterface $ translator )
58
+ public function __construct (Factory $ validator , TranslatorInterface $ translator, Cache $ cache )
51
59
{
52
60
$ this ->validator = $ validator ;
53
61
$ this ->translator = $ translator ;
62
+ $ this ->cache = $ cache ;
54
63
}
55
64
56
65
/**
@@ -88,6 +97,10 @@ protected function getMessages()
88
97
*/
89
98
protected function getAttributeNames ()
90
99
{
100
+ if ($ this ->cache ->get (self ::$ CORE_VALIDATION_CACHE_KEY ) !== null ) {
101
+ return $ this ->cache ->get (self ::$ CORE_VALIDATION_CACHE_KEY );
102
+ }
103
+
91
104
$ extId = $ this ->getClassExtensionId ();
92
105
$ attributeNames = [];
93
106
@@ -96,6 +109,8 @@ protected function getAttributeNames()
96
109
$ attributeNames [$ attribute ] = $ this ->translator ->trans ($ key );
97
110
}
98
111
112
+ $ this ->cache ->forever (self ::$ CORE_VALIDATION_CACHE_KEY , $ attributeNames );
113
+
99
114
return $ attributeNames ;
100
115
}
101
116
0 commit comments