@@ -86,9 +86,7 @@ public static function fake(array $values, bool $loadMissingValues = true): self
8686
8787 final public function __construct (array $ values = [])
8888 {
89- $ this ->ensureConfigIsLoaded ();
90-
91- foreach ($ this ->config ->getReflectedProperties () as $ name => $ property ) {
89+ foreach ($ this ->settingsConfig ()->getReflectedProperties () as $ name => $ property ) {
9290 if (method_exists ($ property , 'isReadOnly ' ) && $ property ->isReadOnly ()) {
9391 continue ;
9492 }
@@ -140,25 +138,28 @@ public function __serialize(): array
140138 /** @var Collection $encrypted */
141139 /** @var Collection $nonEncrypted */
142140 [$ encrypted , $ nonEncrypted ] = $ this ->toCollection ()->partition (
143- fn ($ value , string $ name ) => $ this ->config ->isEncrypted ($ name )
141+ fn ($ value , string $ name ) => $ this ->settingsConfig () ->isEncrypted ($ name )
144142 );
145143
146144 return array_merge (
147145 $ encrypted ->map (fn ($ value ) => Crypto::encrypt ($ value ))->all (),
148- $ nonEncrypted ->all ()
146+ $ nonEncrypted ->all (),
147+ ['_settingsLoadedFromCache ' => $ this ->settingsConfig ()->isLoadedFromCache ()]
149148 );
150149 }
151150
152151 public function __unserialize (array $ data ): void
153152 {
154153 $ this ->loaded = false ;
155154
156- $ this ->ensureConfigIsLoaded ();
155+ $ settingsLoadedFromCache = $ data ['_settingsLoadedFromCache ' ] ?? null ;
156+ unset($ data ['_settingsLoadedFromCache ' ]);
157+ $ this ->settingsConfig ()->markLoadedFromCache ($ settingsLoadedFromCache ?? false );
157158
158159 /** @var Collection $encrypted */
159160 /** @var Collection $nonEncrypted */
160161 [$ encrypted , $ nonEncrypted ] = collect ($ data )->partition (
161- fn ($ value , string $ name ) => $ this ->config ->isEncrypted ($ name )
162+ fn ($ value , string $ name ) => $ this ->settingsConfig () ->isEncrypted ($ name )
162163 );
163164
164165 $ data = array_merge (
@@ -201,16 +202,12 @@ public function save(): self
201202
202203 public function lock (string ...$ properties )
203204 {
204- $ this ->ensureConfigIsLoaded ();
205-
206- $ this ->config ->lock (...$ properties );
205+ $ this ->settingsConfig ()->lock (...$ properties );
207206 }
208207
209208 public function unlock (string ...$ properties )
210209 {
211- $ this ->ensureConfigIsLoaded ();
212-
213- $ this ->config ->unlock (...$ properties );
210+ $ this ->settingsConfig ()->unlock (...$ properties );
214211 }
215212
216213 public function isLocked (string $ property ): bool
@@ -225,16 +222,12 @@ public function isUnlocked(string $property): bool
225222
226223 public function getLockedProperties (): array
227224 {
228- $ this ->ensureConfigIsLoaded ();
229-
230- return $ this ->config ->getLocked ()->toArray ();
225+ return $ this ->settingsConfig ()->getLocked ()->toArray ();
231226 }
232227
233228 public function toCollection (): Collection
234229 {
235- $ this ->ensureConfigIsLoaded ();
236-
237- return $ this ->config
230+ return $ this ->settingsConfig ()
238231 ->getReflectedProperties ()
239232 ->mapWithKeys (fn (ReflectionProperty $ property ) => [
240233 $ property ->getName () => $ this ->{$ property ->getName ()},
@@ -258,21 +251,26 @@ public function toResponse($request)
258251
259252 public function getRepository (): SettingsRepository
260253 {
261- $ this ->ensureConfigIsLoaded ();
262-
263- return $ this ->config ->getRepository ();
254+ return $ this ->settingsConfig ()->getRepository ();
264255 }
265256
266257 public function refresh (): self
267258 {
268- $ this ->config ->clearCachedLockedProperties ();
259+ $ this ->settingsConfig () ->clearCachedLockedProperties ();
269260
270261 $ this ->loaded = false ;
271262 $ this ->loadValues ();
272263
273264 return $ this ;
274265 }
275266
267+ public function settingsConfig (): SettingsConfig
268+ {
269+ $ this ->ensureConfigIsLoaded ();
270+
271+ return $ this ->config ;
272+ }
273+
276274 private function loadValues (?array $ values = null ): self
277275 {
278276 if ($ this ->loaded ) {
@@ -286,7 +284,7 @@ private function loadValues(?array $values = null): self
286284 $ this ->fill ($ values );
287285 $ this ->originalValues = collect ($ values );
288286
289- event (new SettingsLoaded ($ this ));
287+ event (new SettingsLoaded ($ this , $ this -> settingsConfig ()-> isLoadedFromCache () ));
290288
291289 return $ this ;
292290 }
0 commit comments