@@ -31,29 +31,33 @@ public function __construct(Container $container)
31
31
* @var array Base (non-namespaced) vuex state.
32
32
* @var array Base (non-namespaced) lazily evaluated vuex state.
33
33
*/
34
- protected $ _state = [],
35
- $ _lazyState = [];
34
+ protected $ _state = [];
35
+
36
+ protected $ _lazyState = [];
36
37
37
38
/**
38
39
* @var array Vuex modules.
39
40
* @var array Lazily evaluated Vuex modules.
40
41
*/
41
- protected $ _modules = [],
42
- $ _lazyModules = [];
42
+ protected $ _modules = [];
43
+
44
+ protected $ _lazyModules = [];
43
45
44
46
/**
45
47
* @var array Mutations to be committed.
46
48
* @var array Lazy Evaluated mutations to be committed.
47
49
*/
48
- protected $ _mutations = [],
49
- $ _lazyMutations = [];
50
+ protected $ _mutations = [];
51
+
52
+ protected $ _lazyMutations = [];
50
53
51
54
/**
52
55
* @var array Actions to be dispatched.
53
56
* @var array Lazily Evaluated actions to be dispatched.
54
57
*/
55
- protected $ _actions = [],
56
- $ _lazyActions = [];
58
+ protected $ _actions = [];
59
+
60
+ protected $ _lazyActions = [];
57
61
58
62
/** @var array Registered Classes for vuex ModuleLoaders. */
59
63
protected $ registeredMappings = [];
@@ -75,7 +79,7 @@ public function register($mappings)
75
79
76
80
return [
77
81
$ loader ->getNamespace () => [
78
- 'class ' => $ location ,
82
+ 'class ' => $ location ,
79
83
'methods ' => get_class_methods ($ loader ),
80
84
],
81
85
];
@@ -126,11 +130,11 @@ protected function loadModule(string $namespace, $keys, array $args, bool $lazy)
126
130
$ keys = [$ keys => $ args ];
127
131
}
128
132
129
- if (! isset ($ this ->registeredMappings [$ namespace ])) {
133
+ if (!isset ($ this ->registeredMappings [$ namespace ])) {
130
134
throw new VuexInvalidModuleException ("VuexLoader ' {$ namespace }' has not been properly registered. " );
131
135
}
132
136
133
- if (! is_array ($ keys )) {
137
+ if (!is_array ($ keys )) {
134
138
throw new VuexInvalidKeyException ('Invalid keys were passed to Vuex::load. ' );
135
139
}
136
140
@@ -142,15 +146,15 @@ protected function loadModule(string $namespace, $keys, array $args, bool $lazy)
142
146
return is_int ($ key ) ? [$ value => null ] : [$ key => $ value ];
143
147
})
144
148
->each (function ($ args , $ key ) use ($ namespace , $ moduleLoader , $ lazy ) {
145
- if (! in_array ($ key , $ this ->registeredMappings [$ namespace ]['methods ' ])) {
149
+ if (!in_array ($ key , $ this ->registeredMappings [$ namespace ]['methods ' ])) {
146
150
throw new VuexInvalidKeyException ("Method ' {$ key }' does not exist on ' {$ this ->registeredMappings [$ namespace ]['class ' ]}' " );
147
151
}
148
152
149
- if (! is_array ($ args )) {
153
+ if (!is_array ($ args )) {
150
154
$ args = [$ args ];
151
155
}
152
156
153
- $ params = $ this ->resolveClassMethodDependencies ( $ args , $ moduleLoader , $ key );
157
+ $ params = $ this ->resolveClassMethodDependencies ($ args , $ moduleLoader , $ key );
154
158
155
159
if ($ lazy ) {
156
160
Vuex::module (
@@ -159,7 +163,7 @@ protected function loadModule(string $namespace, $keys, array $args, bool $lazy)
159
163
$ key => function () use ($ moduleLoader , $ key , $ params ) {
160
164
return $ moduleLoader ->{$ key }(...array_values ($ params ));
161
165
},
162
- ]
166
+ ]
163
167
);
164
168
} else {
165
169
Vuex::module (
@@ -214,7 +218,7 @@ public function state($state)
214
218
*/
215
219
public function module (string $ namespace , $ state )
216
220
{
217
- if (! is_string ($ namespace ) || empty ($ namespace )) {
221
+ if (!is_string ($ namespace ) || empty ($ namespace )) {
218
222
throw new VuexInvalidModuleException ('$namespace must be a string. ' );
219
223
}
220
224
@@ -237,61 +241,61 @@ public function toArray()
237
241
{
238
242
$ store = [];
239
243
240
- if (! empty ($ this ->_state ) || ! empty ($ this ->_lazyState )) {
244
+ if (!empty ($ this ->_state ) || !empty ($ this ->_lazyState )) {
241
245
$ store ['state ' ] = [];
242
246
}
243
247
244
- if (! empty ($ this ->_modules ) || ! empty ($ this ->_lazyModules )) {
248
+ if (!empty ($ this ->_modules ) || !empty ($ this ->_lazyModules )) {
245
249
$ store ['modules ' ] = [];
246
250
}
247
251
248
- if (! empty ($ this ->_mutations ) || ! empty ($ this ->_lazyMutations )) {
252
+ if (!empty ($ this ->_mutations ) || !empty ($ this ->_lazyMutations )) {
249
253
$ store ['mutations ' ] = [];
250
254
}
251
255
252
- if (! empty ($ this ->_actions ) || ! empty ($ this ->_lazyActions )) {
256
+ if (!empty ($ this ->_actions ) || !empty ($ this ->_lazyActions )) {
253
257
$ store ['actions ' ] = [];
254
258
}
255
259
256
- if (! empty ($ this ->_state )) {
260
+ if (!empty ($ this ->_state )) {
257
261
$ store ['state ' ] = $ this ->reduceData ($ this ->_state , $ store ['state ' ], function ($ acc , $ cur ) {
258
262
return array_merge_phase ($ acc , $ this ->generateState ($ cur ));
259
263
});
260
264
}
261
265
262
- if (! empty ($ this ->_lazyState )) {
266
+ if (!empty ($ this ->_lazyState )) {
263
267
$ store ['state ' ] = $ this ->reduceData ($ this ->_lazyState , $ store ['state ' ], function ($ acc , $ cur ) {
264
268
return array_merge_phase ($ acc , $ this ->generateLazyState ($ cur ));
265
269
});
266
270
}
267
271
268
- if (! empty ($ this ->_modules )) {
272
+ if (!empty ($ this ->_modules )) {
269
273
foreach ($ this ->_modules as $ module ) {
270
274
$ store ['modules ' ] = array_merge_phase ($ store ['modules ' ], $ this ->generateNamespacedModules ($ module ));
271
275
}
272
276
}
273
277
274
- if (! empty ($ this ->_lazyModules )) {
278
+ if (!empty ($ this ->_lazyModules )) {
275
279
foreach ($ this ->_lazyModules as $ module ) {
276
280
$ store ['modules ' ] = array_merge_phase ($ store ['modules ' ], $ this ->generateLazyNamespacedModules ($ module ));
277
281
}
278
282
}
279
283
280
- if (! empty ($ this ->_mutations )) {
284
+ if (!empty ($ this ->_mutations )) {
281
285
$ store ['mutations ' ] = $ this ->_mutations ;
282
286
}
283
287
284
- if (! empty ($ this ->_lazyMutations )) {
288
+ if (!empty ($ this ->_lazyMutations )) {
285
289
foreach ($ this ->_lazyMutations as $ mutation => $ value ) {
286
290
array_push ($ store ['mutations ' ], [$ mutation , $ value ()]);
287
291
}
288
292
}
289
293
290
- if (! empty ($ this ->_actions )) {
294
+ if (!empty ($ this ->_actions )) {
291
295
$ store ['actions ' ] = $ this ->_actions ;
292
296
}
293
297
294
- if (! empty ($ this ->_lazyActions )) {
298
+ if (!empty ($ this ->_lazyActions )) {
295
299
foreach ($ this ->_lazyActions as $ action => $ value ) {
296
300
array_push ($ store ['actions ' ], [$ action , $ value ()]);
297
301
}
@@ -300,27 +304,29 @@ public function toArray()
300
304
return $ store ;
301
305
}
302
306
303
- public function recursiveGet (array $ selectors , array $ data ) {
307
+ public function recursiveGet (array $ selectors , array $ data )
308
+ {
304
309
// Grab the first item
305
310
$ first = array_shift ($ selectors );
306
311
307
312
if (isset ($ data ['state ' ][$ first ])) {
308
313
// return from state if possible
309
314
return $ data ['state ' ][$ first ];
310
- } else if (isset ($ data ['modules ' ][$ first ])) {
315
+ } elseif (isset ($ data ['modules ' ][$ first ])) {
311
316
// pass to nested module and check its state
312
317
return $ this ->recursiveGet ($ selectors , $ data ['modules ' ][$ first ]);
313
- }
318
+ }
314
319
315
- // all unfound items will happily return null (no errors)
316
- return null ;
320
+ // all unfound items will happily return null (no errors)
321
+ return null ;
317
322
}
318
323
319
324
/**
320
325
* Usage: to get this.$store.state.users.active.name
321
326
* Vuex::get('users.active.name')
322
327
*/
323
- public function get (string $ selector ) {
328
+ public function get (string $ selector )
329
+ {
324
330
$ parts = explode ('. ' , $ selector );
325
331
return $ this ->recursiveGet ($ parts , $ this ->toArray ());
326
332
}
@@ -409,16 +415,16 @@ public function toResponse()
409
415
*/
410
416
public function verifyState ($ state )
411
417
{
412
- if (method_exists ($ state , 'toArray ' )) {
413
- $ state = $ state ->toArray ();
414
- } elseif (is_array ($ state )) {
418
+ if (is_array ($ state )) {
415
419
$ state = collect ($ state )->toArray ();
416
- } elseif (! is_callable ($ state )) {
420
+ } elseif (method_exists ($ state , 'toArray ' )) {
421
+ $ state = $ state ->toArray ();
422
+ } elseif (!is_callable ($ state )) {
417
423
throw new VuexInvalidStateException ('$state must be an array or a Collection. ' );
418
424
}
419
425
420
426
foreach ($ state as $ key => $ value ) {
421
- if (method_exists ($ value , 'toArray ' )) {
427
+ if (method_exists (( object ) $ value , 'toArray ' )) {
422
428
$ state [$ key ] = $ value ->toArray ();
423
429
}
424
430
}
@@ -476,7 +482,7 @@ protected function generateLazyState($state)
476
482
protected function generateNamespacedModules ($ module )
477
483
{
478
484
foreach ($ module as $ namespace => $ state ) {
479
- if (! Str::contains ($ namespace , '/ ' )) { // simple module namespace
485
+ if (!Str::contains ($ namespace , '/ ' )) { // simple module namespace
480
486
return [$ namespace => ['state ' => $ state ]];
481
487
} else { // complex nested modules namespace
482
488
$ namespaces = array_reverse (collect (explode ('/ ' , $ namespace ))->toArray ());
@@ -499,7 +505,7 @@ protected function generateNamespacedModules($module)
499
505
protected function generateLazyNamespacedModules ($ module )
500
506
{
501
507
foreach ($ module as $ namespace => $ state ) {
502
- if (! Str::contains ($ namespace , '/ ' )) { // simple module namespace
508
+ if (!Str::contains ($ namespace , '/ ' )) { // simple module namespace
503
509
if (is_callable ($ state )) {
504
510
$ state = $ state ();
505
511
}
@@ -542,11 +548,11 @@ protected function generateLazyNamespacedModules($module)
542
548
*/
543
549
public function dispatch ($ action , $ value = null )
544
550
{
545
- if (! is_string ($ action ) || empty ($ action )) {
551
+ if (!is_string ($ action ) || empty ($ action )) {
546
552
throw new VuexInvalidModuleException ('$mutation must be a string. ' );
547
553
}
548
554
549
- if (! isset ($ value )) {
555
+ if (!isset ($ value )) {
550
556
array_push ($ this ->_actions , [$ action ]);
551
557
} elseif (is_string ($ value ) || is_bool ($ value ) || is_numeric ($ value )) {
552
558
array_push ($ this ->_actions , [$ action , $ value ]);
@@ -567,11 +573,11 @@ public function dispatch($action, $value = null)
567
573
*/
568
574
public function commit ($ mutation , $ value = null )
569
575
{
570
- if (! is_string ($ mutation ) || empty ($ mutation )) {
576
+ if (!is_string ($ mutation ) || empty ($ mutation )) {
571
577
throw new VuexInvalidModuleException ('$mutation must be a string. ' );
572
578
}
573
579
574
- if (! isset ($ value )) {
580
+ if (!isset ($ value )) {
575
581
array_push ($ this ->_mutations , [$ mutation ]);
576
582
} elseif (is_string ($ value ) || is_bool ($ value ) || is_numeric ($ value )) {
577
583
array_push ($ this ->_mutations , [$ mutation , $ value ]);
0 commit comments