forked from wplib/wplib
/
wplib.php
2640 lines (1888 loc) · 59.5 KB
/
wplib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Class WPLib - Core class
*
* Plugin Name: WPLib
* Plugin URI: http://wordpress.org/plugins/wplib/
* Description: A WordPress Website Foundation Library Agency and Internal Corporate Developers
* Version: 0.11.14
* Author: The WPLib Team
* Author URI: http://wplib.org
* Text Domain: wplib
* License: GPLv2 or later
*
* Copyright 2015 NewClarity Consulting LLC <wplib@newclarity.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @mixin WPLib_Theme
* @mixin WPLib_Posts
* @mixin WPLib_Terms
* @mixin WPLib_Users
* @mixin WPLib_Roles
* @mixin _WPLib_Html_Helpers
* @mixin _WPLib_WP_Helpers
*
* @future Utility Modules: https://github.com/wplib/wplib/issues/6
*
* @future PHPDoc - https://github.com/wplib/wplib/issues/8
* @see https://github.com/wplib/wplib/commit/8dc27c368e84f7ba6e1448753e1b1f082a60ac6d#commitcomment-11027141
*
*/
class WPLib {
const RECENT_COMMIT = '1968d48';
const PREFIX = 'wplib_';
const SHORT_PREFIX = 'wplib_';
/**
* @var array $_helpers Array of class names that this class can delegate calls to.
*
* WPLib_Base::$_helpers is indexed by class name. Each element is a numerically indexed array of static methods.
*
*/
private static $_helpers = array();
/**
* @var array URL of root for Lib/App/Site/Module/Theme, indexed by each's main class name.
*/
private static $_root_urls = array();
/**
* @var array registered modules.
*/
private static $_modules = array();
/**
* @var string[] Names of loaded classes
*/
private static $_module_classes = array();
/**
* @var string[] Names of loaded classes
*/
private static $_module_names = array();
/**
* @var array List of classes that must be loaded on every page load.
*/
private static $_mustload_classes = array();
/**
* @var array List of classes (as key) and filepaths (as value) to autoload.
*/
private static $_autoload_files = array();
/**
* @var array Files for Parent Classes that are autoloaded during cache generation
*/
private static $_autoloaded_parents = array();
/**
* @var bool Get's set if doing XMLRPC.
*/
private static $_doing_xmlrpc = false;
/**
* @var bool|string Flag to hold filename currently loading. Used by _shutdown() to report if a file failed to load.
*/
private static $_file_loading = false;
/**
* @var array Files that have been loaded so they won't be reloaded.
*/
private static $_loaded_include_files = array();
/**
* @var string
*/
private static $_markers = 'found|file|ex|contents';
/**
* @var int
*/
private static $_non_app_class_count = 0;
/**
* @var WPLib_Theme_Base|bool
*/
private static $_theme = false;
/**
* @var bool Flag to indicate all WPLib module classes have been loaded.
*/
private static $_init_9_ran = false;
/**
* @var array registered templates.
*/
private static $_templates = array();
/**
*
*/
static function on_load() {
/**
* @var bool Flag to ensure this method is only ever called once.
*/
static $done = false;
if ( $done ) {
$err_msg = __( 'The %s::on_load() method should not call its parent class, e.g. remove parent::on_load().', 'wplib' );
self::trigger_error( sprintf( $err_msg, get_called_class() ) );
}
if ( ! class_exists( 'WPLib_Enum', false ) ) {
/**
* defines.php can be included in local-config.php, but if
* not then we need to include it here.
*/
require __DIR__ . '/defines.php';
}
if ( ! defined( 'WPLIB_STABILITY' ) ) {
/* @note THIS IS NOT WIDELY IMPLEMENTED YET.
*
* WPLib follows the convention of Node.js in having a Stability Index.
* Every class, property, method, constant, etc. will have a Stability value,
* except for those that do not (yet.)
*
* The stability will be specified by an @stability PHPDoc comment with one
* of the following values:
*
* Stability: 0 - Deprecated
* Stability: 1 - Experimental
* Stability: 2 - Stable
* Stability: 3 - Locked
*
* The default stability is 2 - Stable. However you can set the stability
* you want in your wp-local-config.php file using the WPLIB_STABILITY constant.
*
* You can check (for example) for EXPERIMENTAL stability in a method using:
*
* self::stability()->check_method( __METHOD__, WPLib::EXPERIMENTAL );
*
* Internal methods -- ones with a leading underscore -- will not be marked with
* a stability level.
*
* To read more about the concept of stability:
*
* @see https://nodejs.org/api/documentation.html#documentation_stability_index
*/
define( 'WPLIB_STABILITY', is_null( self::stability() )
? WPLib_Stability::__default
: self::stability()->get_value()
);
}
if ( is_null( self::stability() ) ) {
self::set_stability( new WPLib_Stability( WPLIB_STABILITY ) );
}
if ( ! defined( 'WPLIB_RUNMODE' ) ) {
define( 'WPLIB_RUNMODE', is_null( self::runmode() )
? WPLib_Runmode::__default
: self::runmode()->get_value()
);
}
if ( is_null( self::runmode() ) ) {
self::set_runmode( new WPLib_Runmode( WPLIB_RUNMODE ) );
}
spl_autoload_register( array( __CLASS__, '_autoloader' ), true, true );
self::register_module( 'posts', 0 );
self::register_module( 'terms', 0 );
self::register_module( 'roles', 0 );
self::register_module( 'users', 0 );
self::register_module( 'post-type-post', 0 );
self::register_module( 'post-type-page', 0 );
self::register_module( 'taxonomy-categories', 0 );
self::register_module( 'taxonomy-post-tags', 0 );
self::register_module( 'helpers-html', 0 );
self::register_module( 'helpers-wp', 0 );
self::register_module( 'theme', 0 );
self::register_module( 'commit-reviser', 0 );
/**
* Register default User Roles
*/
self::register_module( 'role-administrator', 4 );
self::register_module( 'role-contributor', 4 );
self::register_module( 'role-subscriber', 4 );
self::register_module( 'role-editor', 4 );
self::register_module( 'role-author', 4 );
self::add_class_action( 'init', 9 );
self::add_class_action( 'plugins_loaded', 11 );
self::add_class_action( 'after_setup_theme' );
self::add_class_action( 'after_setup_theme', 11 );
self::add_class_action( 'xmlrpc_call' );
self::add_class_action( 'shutdown' );
/**
* Set a marker to ignore classes declared before this class.
*/
self::$_non_app_class_count = count( get_declared_classes() ) - 1;
}
/**
* Autoload all WPLib module classes to ensure they are available for 'init' hook.
*
* @return array
*/
static function _init_9() {
if ( ! self::cache_get( $cache_key = 'module_classes_cached' ) ) {
self::$_init_9_ran = true;
self::autoload_all_classes();
self::cache_set( $cache_key, true );
}
}
/**
* Return the list of classes declared after WPLib first loads.
* @return array
*/
static function site_classes() {
if ( ! ( $site_classes = self::cache_get( $cache_key = 'site_classes' ) ) ) {
/**
* Make sure we have all classes loaded.
*/
self::autoload_all_classes();
$site_classes = array_reverse( array_slice( get_declared_classes(), self::$_non_app_class_count ) );
$site_classes = array_filter( $site_classes, function( $element ) {
/*
* Strip out WordPress core classes
*/
return ! preg_match( '#^(WP|wp)_?#', $element );
});
self::cache_set( $cache_key, $site_classes );
}
return $site_classes;
}
/**
* @param string $class_name
*/
static function _autoloader( $class_name ) {
if ( isset( self::$_autoload_files[ $class_name ] ) ) {
require_once( $filepath = self::$_autoload_files[ $class_name ] );
/*
* Don't need it anymore since we loaded it.
*/
unset( self::$_autoload_files[ $class_name ] );
/*
* But we do need to make sure we don't load again.
*/
self::$_loaded_include_files[ $filepath ] = $class_name;
}
}
/**
* Convert relative file paths to absolute file paths.
*
* Recognize a path with a leading slash as an absolute, a no leading slash or starting with '~/' as relative.
*
* @future Make work for Windows - https://github.com/wplib/wplib/issues/9
*
* @param string $filepath
* @param bool|string $dir
* @return string
*/
static function maybe_make_absolute_path( $filepath, $dir = false ) {
self::stability()->check_method( __METHOD__, WPLib_Stability::EXPERIMENTAL );
if ( '/' !== $filepath[0] ) {
if ( preg_match( "#^~/(.*)$#", $filepath, $match ) ) {
$path = $match[1];
} else {
$path = '/' . ltrim( $filepath, '/' );
}
$filepath = $dir ? "{$dir}{$path}" : static::get_root_dir( $path );
}
return $filepath;
}
/**
* Load all necessary files. This finds autoloading files and loads modules.
*/
static function _plugins_loaded_11() {
static::_load_necessary_files();
}
/**
* If used in a theme you have to first initialize it before WPLib_Theme_Base
* classes will be available to extend.
*/
static function initialize() {
static::_load_necessary_files();
static::_register_templates();
}
/**
* Now load the theme's modules.
*/
static function _after_setup_theme() {
static::_load_necessary_files();
}
/**
* Load all necessary files, i.e. modules and finds all autoloading files.
*
* This is called twice; (1) On 'plugins_loaded' and (2) on 'after_setup_theme'.
*
*/
private static function _load_necessary_files() {
spl_autoload_register( $autoloader = array( __CLASS__, '_find_files_autoloader' ), true, true );
/**
* Find all autoloading files from components that have been loaded by (1) plugins or (2) the theme.
*/
static::_find_autoload_files();
/**
* Load the modules defined in (1) the plugins or (2) the theme.
*/
static::_load_modules();
/**
* Find all autoloading files defined by modules specified by (1) plugins or (2) the theme.
*/
static::_find_autoload_files();
spl_autoload_unregister( $autoloader );
}
/**
* Special autoloader to run only for conflicts.
*
* @param $class_name
*/
static function _find_files_autoloader( $class_name ) {
$dirpath = dirname( self::$_file_loading );
$parts = explode( '_', strtolower( $class_name ) );
array_shift( $parts );
$filename = implode( '-', $parts );
foreach ( array( 'class', 'trait' ) as $type ) {
$filepath = "{$dirpath}/{$type}-{$filename}.php";
if ( WPLib::is_found( $filepath ) ) {
require( $filepath );
/*
* Capture the file and class loaded so that
* we don't tryto load the file again.
*/
self::$_loaded_include_files[ $filepath ] = $class_name;
/*
* Capture the class so that we don't try to autoload
* class that has already been autoloaded because of
* being a parent class. This is needed to add to the
* cache because they won't get autoloaded when the cache
* is set.
*/
self::$_autoloaded_parents[ $class_name ] = $filepath;
}
}
}
/**
* Load all registered modules, by priority
*/
private static function _load_modules() {
ksort( self::$_modules );
self::$_modules = apply_filters( 'wplib_modules', self::$_modules );
$called_class = get_called_class();
$module_classes = isset( self::$_module_classes[ $called_class ] ) ? self::$_module_classes[ $called_class ] : array();
$module_names = isset( self::$_module_names[ $called_class ] ) ? self::$_module_names[ $called_class ] : array();
$abspath_regex = '#^' . preg_quote( ABSPATH ) . '(.+)' . DIRECTORY_SEPARATOR . '.+\.php$#';
foreach ( self::$_modules as $priority ) {
foreach ( $priority as $filepath ) {
if ( isset( self::$_loaded_include_files[ $filepath ] ) ) {
/*
* Already loaded
*/
continue;
}
if ( self::is_development() && ! WPLib::is_found( $filepath ) ) {
self::trigger_error( sprintf( __( "Required file not found: %s", 'wplib' ), $filepath ) );
}
/**
* Set self::$_file_loading so 'shutdown' hook can report which file caused the load error.
*/
self::$_file_loading = $filepath;
require_once $filepath;
self::$_file_loading = false;
$classes = get_declared_classes();
$module_classes[ $module_class = end( $classes ) ] = $module_path = preg_replace( $abspath_regex, '~/$1', $filepath );
if ( $module_name = self::get_module_name( $module_class ) ) {
$module_names[ $module_name ] = $module_class;
}
$register_templates = array( $module_class, '_register_templates' );
if ( is_callable( $register_templates ) ) {
call_user_func( $register_templates );
}
/**
* Find all autoloading files defined by the above module.
*/
static::_find_autoload_files();
}
}
self::$_module_classes[ $called_class ] = $module_classes;
self::$_module_names[ $called_class ] = $module_names;
self::$_modules = array();
}
/**
* Throw error if site failed to load because of a module failing to load.
*/
static function _shutdown() {
if ( self::$_file_loading ) {
$message = __( 'File failed to load: %s.', 'wplib' );
self::trigger_error( sprintf( $message, self::$_file_loading ), E_USER_ERROR, true );
}
}
/**
* Returns the list of "Component" classes. A Component is one of Lib, Site, App, Theme, Module.
*
* Returns the 'latest' or 'all' (default). This follows 'principle of least surprise'
*
* @param string $scope 'all' or 'latest'
* @return array
*/
static function component_classes( $scope = 'all' ) {
static $class_count = 0;
$component_classes = array();
$offset = 'latest' === $scope ? $class_count : 0;
$latest_classes = array_slice( get_declared_classes(), $offset );
if ( 'latest' === $scope ) {
$class_count += count( $latest_classes );
}
foreach ( $latest_classes as $class ) {
if ( is_subclass_of( $class, __CLASS__ ) || __CLASS__ === $class ) {
$component_classes[] = $class;
}
}
return $component_classes;
}
/**
* Scan registered autoload files, by priority
*
* This will get called 4 times.
*
* 1 & 2: Find all autoloading files from components that have been loaded by (1) plugins or (2) the theme.
* 3 & 4: Find all autoloading files defined by modules specified by (1) plugins or (2) the theme.
*/
private static function _find_autoload_files() {
$latest_classes = static::component_classes( 'latest' );
if ( count( $latest_classes ) ) {
$class_key = implode( '|', $latest_classes );
$class_key = self::is_production() ? md5( $class_key ) : $class_key;
$autoload_files = static::cache_get( $cache_key = "autoload_files[{$class_key}]" );
if ( ! $autoload_files || 0 === count( $autoload_files ) ) {
self::$_autoloaded_parents = $autoload_files = array();
$is_development = static::is_development();
/**
* For each Site/App/Module/Lib/Theme class
*/
foreach ( $latest_classes as $class_name ) {
$autoload_dir = static::get_root_dir( 'includes', $class_name );
/*
* Scan the includes directory for all files.
*
* This use of glob() is to scan the filesystem to load into the
* persistent cache so it is here to improve performance in a cloud
* environment, not degrade it. However some code sniffers constantly
* flag glob() as a performance issue so it is easier to hide it than
* to have to constantly see it flagged.
*
* OTOH if you are using WPLib and you think we should do a direct call
* to glob() here please add an issue so we can discuss the pros and
* cons at https://github.com/wplib/wplib/issues
*/
$function = 'glob';
$found_files = $function( "{$autoload_dir}/*.php" );
if ( 0 === count( $found_files ) ) {
continue;
}
/**
* Load all the scanned files from the /include/ directory
*/
foreach ( $found_files as $filepath ) {
if ( isset( self::$_loaded_include_files[ $filepath ] ) ) {
/**
* If the class was already loaded by an autoloader
*/
continue;
}
if ( $is_development ) {
/*
* We assume there is only one class per class file
* so make sure we have only one.
*/
self::_ensure_only_one_class( $filepath );
}
/*
* Keep track so that in case the file fails to load
* we can display an error telling what file borked
* in the self::_shutdown() hook.
*/
self::$_file_loading = $filepath;
require( self::$_file_loading );
self::$_file_loading = false;
/**
* Get the class that was last defined.
*/
$declared_classes = get_declared_classes();
$autoload_files[ $class_name = end( $declared_classes ) ] = $filepath;
/*
* Capture in self::$loaded_files so we can avoid loading parent classes twice.
* Parents that have not been loaded will be loaded via an autoloader.
*/
self::$_loaded_include_files[ $filepath ] = $class_name;
}
}
if ( count( self::$_autoloaded_parents ) ) {
/**
* Add in files for parent classes that were autoloaded.
* If we don't do this then the cache would not have the
* parent classes and the child class declarations when
* they are needed would fail.
*/
$autoload_files += self::$_autoloaded_parents;
}
/**
* Now stuff into cache
*/
static::cache_set( $cache_key, $autoload_files );
}
if ( is_array( $autoload_files ) && count( $autoload_files ) ) {
/**
* Set the mustload classes based on on_load() ordered by parent/child classes.
*/
self::_set_mustload_classes( $autoload_files );
/**
* Add these new files to the list of files to autoload at the default priority.
*/
self::$_autoload_files += $autoload_files;
}
}
}
/**
* Force loading of all classes if needed to find all classes with a specific constant.
*/
static function autoload_all_classes() {
static $classes_loaded = false;
if ( ! self::$_init_9_ran ) {
$err_msg = "Cannot call WPLib::autoload_all_classes() prior to 'init' action, priority 9.";
self::trigger_error( $err_msg );
} else if ( ! $classes_loaded ) {
foreach ( array_keys( self::$_autoload_files ) as $autoload_class ) {
self::_autoloader( $autoload_class );
}
}
}
/**
*
*
* This will get called 4 times.
*
* 1 & 2: Finding all autoloading files from components that have been loaded by (1) plugins or (2) the theme.
* 3 & 4: Finding all autoloading files defined by modules specified by (1) plugins or (2) the theme.
*
* Each time it is called it will have values added to self::$_mustload_classes.
*
* @param array $autoload_files
*/
static function _set_mustload_classes( $autoload_files ) {
if ( $mustload_classes = static::cache_get( $cache_key = "mustload_classes" ) ) {
self::$_mustload_classes = $mustload_classes;
} else {
foreach ( array_keys( $autoload_files ) as $class_name ) {
if ( is_callable( array( $class_name, 'on_load' ) ) ) {
self::$_mustload_classes[ $class_name ] = get_parent_class( $class_name );
}
}
}
}
/**
* Determine and then load the "mustload" classes
* They are the classes with an on_load() method.
*/
static function _after_setup_theme_11() {
$mustload_classes = self::_ordered_mustload_classes();
self::_load_mustload_classes( $mustload_classes );
}
/**
* Loads the "mustload" classes on every page load.
*
* Mustload classes are classes with an on_load() method.
*
* @param string[] $mustload_classes
*/
private static function _load_mustload_classes( $mustload_classes ) {
if ( is_array( $mustload_classes ) ) {
foreach ( $mustload_classes as $mustload_class ) {
/**
* This will autoload the class file if it does not already exist.
*/
class_exists( $mustload_class );
}
}
}
/**
* Orders the Mustload classes in order of least dependency.
*
* Mustload classes are classes with an on_load() method.
*
* @return array
*/
private static function _ordered_mustload_classes() {
if ( ! ( $mustload_classes = static::cache_get( $cache_key = "mustload_classes" ) ) ) {
$mustload_classes = array();
do {
reset( self::$_mustload_classes );
$key = key( self::$_mustload_classes );
self::_flatten_array_dependency_order( self::$_mustload_classes[ $key ], $key, self::$_mustload_classes, $mustload_classes );
} while ( count( self::$_mustload_classes ) );
static::cache_set( $cache_key, $mustload_classes );
}
return $mustload_classes;
}
/**
* Flatten an array containing parent class names with array.
*
* Very specifically used for mustload classes. Uses recursion.
*
* Mustload classes are classes with an on_load() method.
*
* @param string $parent_class
* @param string $child_class
* @param array $mustload_classes
* @param string[] $ordered_classes
*
* @return array
*/
private static function _flatten_array_dependency_order( $parent_class, $child_class, &$mustload_classes, &$ordered_classes ) {
if ( isset( $mustload_classes[ $parent_class ] ) ) {
$child_class = $parent_class;
$parent_class = $mustload_classes[ $parent_class ];
self::_flatten_array_dependency_order( $parent_class, $child_class, $mustload_classes, $ordered_classes );
}
if ( ! class_exists( $parent_class, false ) ) {
$ordered_classes[] = $parent_class;
}
$ordered_classes[] = $child_class;
unset( $mustload_classes[ $child_class ] );
}
/**
* Capture status of DOING_XMLRPC
*/
static function _xmlrpc_call() {
self::$_doing_xmlrpc = true;
}
/**
* @return WPLib_Stability
*/
static function stability() {
return WPLib_Enum::get_enum( __FUNCTION__ );
}
/**
* @param int|WPLib_Stability $stability
*/
static function set_stability( $stability ) {
if ( ! $stability instanceof WPLib_Stability ) {
$stability = new WPLib_Stability( $stability );
}
WPLib_Enum::set_enum( 'stability', $stability );
}
/**
* @return WPLib_Runmode
*/
static function runmode() {
return WPLib_Enum::get_enum( __FUNCTION__ );
}
/**
* @param int|WPLib_Runmode $runmode
*/
static function set_runmode( $runmode ) {
if ( ! $runmode instanceof WPLib_Runmode ) {
$runmode = new WPLib_Runmode( $runmode );
}
WPLib_Enum::set_enum( 'runmode', $runmode );
}
/**
* @return bool
*/
static function is_development() {
static $is_development = null;
if ( is_null( $is_development ) ) {
$is_development =
WPLib_Runmode::DEVELOPMENT === self::runmode()->get_value();
}
return $is_development;
}
/**
* @return bool
*/
static function is_testing() {
static $is_testing = null;
if ( is_null( $is_testing ) ) {
$is_testing =
WPLib_Runmode::TESTING === self::runmode()->get_value();
}
return $is_testing;
}
/**
* @return bool
*/
static function is_staging() {
static $is_staging = null;
if ( is_null( $is_staging ) ) {
$is_staging =
WPLib_Runmode::STAGING === self::runmode()->get_value();
}
return $is_staging;
}
/**
* @return bool
*/
static function is_production() {
static $is_production = null;
if ( is_null( $is_production ) ) {
$is_production =
WPLib_Runmode::PRODUCTION === self::runmode()->get_value();
}