@@ -84,11 +84,10 @@ protected static function getStatic() : object
84
84
}
85
85
86
86
/**
87
- * Set plugin config.
87
+ * Init plugin config.
88
88
*
89
89
* @access protected
90
90
* @return void
91
- * @throws ConfigurationException
92
91
*/
93
92
protected function initConfig ()
94
93
{
@@ -144,7 +143,7 @@ protected function parseConfig()
144
143
}
145
144
146
145
/**
147
- * Reset config objects .
146
+ * Reset config object .
148
147
*
149
148
* @access protected
150
149
* @return void
@@ -165,9 +164,13 @@ protected function getConfig(?string $key = null)
165
164
{
166
165
$ this ->initConfig ();
167
166
if ( $ key ) {
168
- return $ this ->global ->{$ key } ?? null ;
167
+ $ data = $ this ->global ->{$ key } ?? null ;
168
+
169
+ } else {
170
+ $ data = $ this ->global ;
169
171
}
170
- return $ this ->global ;
172
+ $ this ->resetConfig ();
173
+ return $ data ;
171
174
}
172
175
173
176
/**
@@ -189,14 +192,47 @@ protected function updateConfig(array $options = [], $args = 64|128|256) : bool
189
192
}
190
193
}
191
194
192
- $ data ['routes ' ] = (object )$ data ['routes ' ];
193
- $ data ['cron ' ] = (object )$ data ['cron ' ];
194
- $ data ['assets ' ] = (object )$ data ['assets ' ];
195
+ $ data ['cron ' ] = (object )$ data ['cron ' ];
196
+ $ data ['hooks ' ] = (object )$ data ['hooks ' ];
197
+ $ data ['settings ' ] = (object )$ data ['settings ' ];
198
+ $ data ['inputs ' ] = (object )$ data ['inputs ' ];
199
+ $ data ['assets ' ] = (object )$ data ['assets ' ];
200
+
195
201
$ data = $ this ->formatJson ($ data , $ args );
196
-
197
202
return $ this ->writeFile ($ this ->getRoot ($ this ->config ), $ data );
198
203
}
199
204
205
+ /**
206
+ * Load configuration file.
207
+ *
208
+ * @access protected
209
+ * @param string $config
210
+ * @param bool $isArray
211
+ * @return mixed
212
+ */
213
+ protected function loadConfig (string $ config , bool $ isArray = false )
214
+ {
215
+ $ value = false ;
216
+ $ dir = dirname ($ this ->getRoot ($ this ->config ));
217
+
218
+ if ( $ this ->cacheable ) {
219
+ $ key = $ this ->applyPrefix ($ config );
220
+ if ( !($ value = $ this ->getTransient ($ key )) ) {
221
+ if ( $ this ->isFile ( ($ json = "{$ dir }/ {$ config }.json " ) ) ) {
222
+ $ value = $ this ->decodeJson ($ this ->readfile ($ json ), $ isArray );
223
+ }
224
+ $ this ->setTransient ($ key , $ value , 0 );
225
+ }
226
+
227
+ } else {
228
+ if ( $ this ->isFile ( ($ json = "{$ dir }/ {$ config }.json " ) ) ) {
229
+ $ value = $ this ->decodeJson ($ this ->readfile ($ json ), $ isArray );
230
+ }
231
+ }
232
+
233
+ return $ value ;
234
+ }
235
+
200
236
/**
201
237
* Set global config path.
202
238
*
@@ -210,7 +246,7 @@ protected function setConfigPath($path = '/global.json')
210
246
}
211
247
212
248
/**
213
- * Get dynamic root.
249
+ * Get dynamic relative root.
214
250
*
215
251
* @access protected
216
252
* @param string $sub
@@ -229,7 +265,7 @@ protected function getRoot(?string $sub = null) : string
229
265
}
230
266
231
267
/**
232
- * Get dynamic namespace.
268
+ * Get dynamic namespace by root .
233
269
*
234
270
* @access protected
235
271
* @return string
@@ -408,7 +444,7 @@ protected function getTempPath(?string $sub = null) : string
408
444
}
409
445
410
446
/**
411
- * Get static expire .
447
+ * Get static TTL .
412
448
*
413
449
* @access protected
414
450
* @return int
@@ -419,6 +455,32 @@ protected function getExpireIn() : int
419
455
$ data = $ config ->ttl ?? 0 ;
420
456
return (int )$ data ;
421
457
}
458
+
459
+ /**
460
+ * Get static timeout.
461
+ *
462
+ * @access protected
463
+ * @return int
464
+ */
465
+ protected function getTimeout () : int
466
+ {
467
+ $ config = $ this ->getConfig ('options ' );
468
+ $ data = $ config ->timeout ?? 0 ;
469
+ return (int )$ data ;
470
+ }
471
+
472
+ /**
473
+ * Get static secret key.
474
+ *
475
+ * @access protected
476
+ * @return string
477
+ */
478
+ protected function getSecret () : string
479
+ {
480
+ $ config = $ this ->getConfig ('options ' );
481
+ $ data = $ config ->secret ?? 0 ;
482
+ return (string )$ data ;
483
+ }
422
484
423
485
/**
424
486
* Get static view path.
@@ -505,6 +567,7 @@ protected function getAjax() : object
505
567
if ( !($ data = $ this ->loadConfig ('ajax ' )) ) {
506
568
$ data = $ this ->global ->ajax ?? [];
507
569
}
570
+ $ this ->resetConfig ();
508
571
return (object )$ data ;
509
572
}
510
573
@@ -544,6 +607,7 @@ protected function getPluginRoles() : array
544
607
if ( !($ data = $ this ->loadConfig ('roles ' , true )) ) {
545
608
$ data = $ this ->global ->roles ?? [];
546
609
}
610
+ $ this ->resetConfig ();
547
611
return (array )$ data ;
548
612
}
549
613
@@ -559,22 +623,24 @@ protected function getCron() : array
559
623
if ( !($ data = $ this ->loadConfig ('cron ' , true )) ) {
560
624
$ data = $ this ->global ->cron ?? [];
561
625
}
626
+ $ this ->resetConfig ();
562
627
return (array )$ data ;
563
628
}
564
629
565
630
/**
566
631
* Get api routes.
567
632
*
568
633
* @access protected
569
- * @return object
634
+ * @return array
570
635
*/
571
- protected function getRoutes () : object
636
+ protected function getRoutes () : array
572
637
{
573
638
$ this ->initConfig ();
574
- if ( !($ data = $ this ->loadConfig ('routes ' )) ) {
639
+ if ( !($ data = $ this ->loadConfig ('routes ' , true )) ) {
575
640
$ data = $ this ->global ->routes ?? [];
576
641
}
577
- return (object )$ data ;
642
+ $ this ->resetConfig ();
643
+ return (array )$ data ;
578
644
}
579
645
580
646
/**
@@ -589,6 +655,7 @@ protected function getRequirements() : object
589
655
if ( !($ data = $ this ->loadConfig ('requirements ' )) ) {
590
656
$ data = $ this ->global ->requirements ?? [];
591
657
}
658
+ $ this ->resetConfig ();
592
659
return (object )$ data ;
593
660
}
594
661
@@ -604,6 +671,23 @@ protected function getHooks() : array
604
671
if ( !($ data = $ this ->loadConfig ('hooks ' , true )) ) {
605
672
$ data = $ this ->global ->hooks ?? [];
606
673
}
674
+ $ this ->resetConfig ();
675
+ return (array )$ data ;
676
+ }
677
+
678
+ /**
679
+ * Get settings inputs.
680
+ *
681
+ * @access protected
682
+ * @return array
683
+ */
684
+ protected function getInputs () : array
685
+ {
686
+ $ this ->initConfig ();
687
+ if ( !($ data = $ this ->loadConfig ('inputs ' , true )) ) {
688
+ $ data = $ this ->global ->inputs ?? [];
689
+ }
690
+ $ this ->resetConfig ();
607
691
return (array )$ data ;
608
692
}
609
693
@@ -619,6 +703,7 @@ protected function getSettings() : array
619
703
if ( !($ data = $ this ->loadConfig ('settings ' , true )) ) {
620
704
$ data = $ this ->global ->settings ?? [];
621
705
}
706
+ $ this ->resetConfig ();
622
707
return (array )$ data ;
623
708
}
624
709
@@ -651,6 +736,7 @@ protected function getAssets() : array
651
736
if ( !($ data = $ this ->loadConfig ('assets ' , true )) ) {
652
737
$ data = $ this ->global ->assets ?? [];
653
738
}
739
+ $ this ->resetConfig ();
654
740
return (array )$ data ;
655
741
}
656
742
@@ -728,6 +814,7 @@ protected function getStrings() : array
728
814
if ( !($ data = $ this ->loadConfig ('strings ' , true )) ) {
729
815
$ data = $ this ->global ->strings ?? [];
730
816
}
817
+ $ this ->resetConfig ();
731
818
return (array )$ data ;
732
819
}
733
820
@@ -784,34 +871,31 @@ protected function getEnv() : string
784
871
}
785
872
786
873
/**
787
- * Load configuration file .
874
+ * Get plugin remote server .
788
875
*
789
876
* @access protected
790
- * @param string $config
791
- * @param bool $isArray
792
- * @return mixed
877
+ * @return array
793
878
*/
794
- protected function loadConfig ( string $ config , bool $ isArray = false )
879
+ protected function getRemoteServer () : array
795
880
{
796
- $ value = false ;
797
- $ dir = dirname ($ this ->getRoot ($ this ->config ));
798
-
799
- if ( $ this ->cacheable ) {
800
- $ key = $ this ->applyPrefix ($ config );
801
- if ( !($ value = $ this ->getTransient ($ key )) ) {
802
- if ( $ this ->isFile ( ($ json = "{$ dir }/ {$ config }.json " ) ) ) {
803
- $ value = $ this ->decodeJson ($ this ->readfile ($ json ), $ isArray );
804
- }
805
- $ this ->setTransient ($ key , $ value , 0 );
806
- }
807
-
808
- } else {
809
- if ( $ this ->isFile ( ($ json = "{$ dir }/ {$ config }.json " ) ) ) {
810
- $ value = $ this ->decodeJson ($ this ->readfile ($ json ), $ isArray );
811
- }
881
+ $ this ->initConfig ();
882
+ if ( !($ data = $ this ->loadConfig ('remote ' , true )) ) {
883
+ $ data = $ this ->global ->remote ?? [];
812
884
}
885
+ $ this ->resetConfig ();
886
+ return (array )$ data ;
887
+ }
813
888
814
- return $ value ;
889
+ /**
890
+ * Get plugin remote server host.
891
+ *
892
+ * @access protected
893
+ * @return string
894
+ */
895
+ protected function getHost () : string
896
+ {
897
+ $ host = $ this ->getRemoteServer ()['host ' ] ?? false ;
898
+ return $ host ?: '' ;
815
899
}
816
900
817
901
/**
0 commit comments