File tree 2 files changed +19
-17
lines changed 2 files changed +19
-17
lines changed Original file line number Diff line number Diff line change 3
3
namespace JamesWildDev \ReactNativeAppHelpers ;
4
4
5
5
use Illuminate \Support \Facades \Route ;
6
+ use Illuminate \Support \Arr ;
6
7
7
8
/**
8
9
* Represents a sync API as a whole. Use this to configure your API once, then
@@ -107,11 +108,7 @@ public function generateRoutes(): void
107
108
foreach ($ this ->constants as $ constant ) {
108
109
$ key = $ constant ->generateCamelCasedName ();
109
110
110
- $ data = $ constant ->value ;
111
- ksort ($ data );
112
- $ version = hash ('sha1 ' , json_encode ($ data ));
113
-
114
- $ singletons [$ key ] = compact ('version ' );
111
+ $ singletons [$ key ] = Arr::only ($ constant ->getCachedValue (), 'version ' );
115
112
}
116
113
117
114
$ collections = [];
Original file line number Diff line number Diff line change @@ -98,23 +98,28 @@ public function hashData(array $data): string
98
98
return hash ('sha1 ' , json_encode ($ data ));
99
99
}
100
100
101
- public function generateConstantRoutes (): void
101
+ public function getCachedValue ()
102
102
{
103
- $ kebabCasedName = $ this ->generateKebabCasedName ();
104
-
105
- Route::get (
106
- $ kebabCasedName ,
107
- function () use ($ kebabCasedName ) {
108
- $ data = Cache::remember (
109
- 'sync_api_constant_ ' . $ kebabCasedName ,
110
- 3600 ,
111
- $ this ->valueFactory
112
- );
103
+ return Cache::remember (
104
+ 'sync-api-constant- ' . $ this ->generateKebabCasedName (),
105
+ 3600 ,
106
+ function () {
107
+ $ data = ($ this ->valueFactory )();
113
108
114
109
return [
115
- 'version ' => $ this ->hashData ($ data ),
116
110
'data ' => $ data ,
111
+ 'version ' => hash ('sha1 ' , json_encode ($ data )),
117
112
];
113
+ }
114
+ );
115
+ }
116
+
117
+ public function generateConstantRoutes (): void
118
+ {
119
+ Route::get (
120
+ $ this ->generateKebabCasedName (),
121
+ function () {
122
+ return $ this ->getCachedValue ();
118
123
},
119
124
);
120
125
}
You can’t perform that action at this time.
0 commit comments