/
oik-api-status.php
174 lines (158 loc) · 4.23 KB
/
oik-api-status.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
<?php // (C) Copyright Bobbing Wide 2014-2017
/**
* Reports the current status of the system
*
* @param bool $detail - show details
*
*/
function oikai_api_status( $detail=false ) {
oikai_api_status_functions();
oikai_api_status_classes();
oikai_api_status_files( $detail );
oikai_api_status_constants();
//oikai_api_status_plugins();
}
/**
* Report the current status of the system with timing
*
* These functions may be used in some fancy front-end dashboard
* so we'll need them to be usable to query values as well as display them
* How and when we show "details" is an interesting question
*/
function oikai_api_status_timer( $detail=false, $text=null ) {
$elapsed = timer_stop( false, 6 );
h3( $text );
p( "Load time (secs): $elapsed " );
oikai_api_status( $detail );
bw_flush();
timer_start();
}
/**
* Display the status of "functions" - both PHP internal and user defined
*/
function oikai_api_status_functions() {
$defined_functions = get_defined_functions();
$internal = bw_array_get( $defined_functions, "internal", null );
$count = count( $internal );
p( "Internal functions: $count " );
$user = bw_array_get( $defined_functions, "user", null );
$count = count( $user );
p( "User functions: $count " );
}
/**
* Displays details of classes.
*
* @param array $classes
*/
function oikai_api_status_classes_details( $classes ) {
if ( $classes ) {
//bw_trace2( $classes );
asort( $classes );
stag( "table" );
foreach ( $classes as $key => $class ) {
stag( "tr" );
stag( "td" );
oikai_handle_reference_type_class( $class. "::", "class" );
etag( "td" );
etag( "tr" );
}
etag( "table" );
}
}
/**
* Displays status of classes
*
* @param bool $detail - future use
*/
function oikai_api_status_classes( $detail=false ) {
$declared_classes = get_declared_classes();
$count = count( $declared_classes );
p( "Classes: $count " );
//oikai_api_status_classes_details( $declared_classes );
}
/**
* Print out the details of the PHP user constants
*
* We don't print out all the PHP ones since there are far too many
*
* @param array $userc - user constants
*/
function oikai_api_status_constants_details( $userc ) {
if ( $userc ) {
ksort( $userc );
foreach ( $userc as $key => $value ) {
//bw_tablerow( $key, $value );
if ( substr( $key, 0,2 ) != "DB" ) {
p( "$key: $value " );
}
}
}
}
function oikai_api_status_constants() {
$constants = get_defined_constants( true );
$userc = bw_array_get( $constants, "user", null );
$count = count( $userc );
p( "User constants: $count" );
// oikai_api_status_constants_details( $userc );
}
function oikai_api_status_files_details( $files ) {
if ( $files ) {
ksort( $files );
foreach ( $files as $key => $file ) {
p( "$key: $file " );
}
}
}
function oikai_api_status_files( $detail = false ) {
$included_files = get_included_files();
$count = count( $included_files );
p( "Included files: $count" );
if ( $detail ) {
oikai_api_status_files_details( $included_files );
}
}
/**
* Get plugin status.
*
* Not available in oik-batch.
* @TODO We need to know if DB functions are available
*
*/
function oikai_api_status_plugins( $detail=false ) {
$plugins = oikai_query_plugins();
$count = oikai_query_plugin_count( $plugins );
p( "Active plugins: $count" );
return( $plugins );
}
/**
* Queries number of plugins
*
* @param array|null $plugins
* @return integer count of plugins - never expected to be 0
*/
function oikai_query_plugin_count( $plugins=null ) {
if ( !$plugins ) {
$plugins = oikai_query_plugins();
}
$count = count( $plugins );
return( $count );
}
/**
* Queries plugins.
*
* Calls bw_get_active_plugins only if WordPress is active.
* @TODO Validate sequence of tests. Could we check bw_is_wordpress() first?
*
* @return array active plugins
*/
function oikai_query_plugins() {
if ( php_sapi_name() == "cli" ) {
$plugins = array( "oik-batch" );
} elseif ( bw_is_wordpress() ) {
oik_require_lib( "oik-depends" );
$plugins = bw_get_active_plugins();
} else {
$plugins = array( "oik-batch" );
}
return( $plugins );
}