99
1010namespace Flarum \Foundation ;
1111
12+ use Illuminate \Contracts \Cache \Store as Cache ;
1213use Illuminate \Support \Arr ;
1314use Illuminate \Validation \Factory ;
1415use Illuminate \Validation \ValidationException ;
@@ -18,6 +19,8 @@ abstract class AbstractValidator
1819{
1920 use ExtensionIdTrait;
2021
22+ public static string $ CORE_VALIDATION_CACHE_KEY = 'core.validation.extension_id_class_names ' ;
23+
2124 /**
2225 * @var array
2326 */
@@ -43,14 +46,20 @@ public function addConfiguration($callable)
4346 */
4447 protected $ translator ;
4548
49+ /**
50+ * @var Cache
51+ */
52+ protected $ cache ;
53+
4654 /**
4755 * @param Factory $validator
4856 * @param TranslatorInterface $translator
4957 */
50- public function __construct (Factory $ validator , TranslatorInterface $ translator )
58+ public function __construct (Factory $ validator , TranslatorInterface $ translator, Cache $ cache )
5159 {
5260 $ this ->validator = $ validator ;
5361 $ this ->translator = $ translator ;
62+ $ this ->cache = $ cache ;
5463 }
5564
5665 /**
@@ -88,6 +97,10 @@ protected function getMessages()
8897 */
8998 protected function getAttributeNames ()
9099 {
100+ if ($ this ->cache ->get (self ::$ CORE_VALIDATION_CACHE_KEY ) !== null ) {
101+ return $ this ->cache ->get (self ::$ CORE_VALIDATION_CACHE_KEY );
102+ }
103+
91104 $ extId = $ this ->getClassExtensionId ();
92105 $ attributeNames = [];
93106
@@ -96,6 +109,8 @@ protected function getAttributeNames()
96109 $ attributeNames [$ attribute ] = $ this ->translator ->trans ($ key );
97110 }
98111
112+ $ this ->cache ->forever (self ::$ CORE_VALIDATION_CACHE_KEY , $ attributeNames );
113+
99114 return $ attributeNames ;
100115 }
101116
0 commit comments