|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\Castor\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
class Development |
|
6
|
|
|
{ |
|
7
|
|
|
public $templatePaths = []; |
|
8
|
|
|
|
|
9
|
|
|
public function capture() |
|
10
|
|
|
{ |
|
11
|
|
|
ob_start(); |
|
12
|
|
|
call_user_func_array( [$this, 'printF'], func_get_args() ); |
|
13
|
|
|
return ob_get_clean(); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function className() |
|
17
|
|
|
{ |
|
18
|
|
|
return $this->isDev() && in_array( DEV, ['css', true] ) |
|
19
|
|
|
? 'dev' |
|
20
|
|
|
: ''; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function debug() |
|
24
|
|
|
{ |
|
25
|
|
|
call_user_func_array( [$this, 'printF'], func_get_args() ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function isDev() |
|
29
|
|
|
{ |
|
30
|
|
|
return defined( 'DEV' ) && !!DEV && WP_ENV == 'development'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function isProduction() |
|
34
|
|
|
{ |
|
35
|
|
|
return WP_ENV == 'production'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function printFiltersFor( $hook = '' ) |
|
39
|
|
|
{ |
|
40
|
|
|
global $wp_filter; |
|
41
|
|
|
if( empty( $hook ) || !isset( $wp_filter[$hook] ))return; |
|
42
|
|
|
$this->printF( $wp_filter[ $hook ] ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function printTemplatePaths() |
|
46
|
|
|
{ |
|
47
|
|
|
if( $this->isDev() && ( DEV == 'templates' || DEV === true )) { |
|
48
|
|
|
$templates = array_keys( array_flip( $this->templatePaths )); |
|
49
|
|
|
$templates = array_map( function( $key, $value ) { |
|
50
|
|
|
return sprintf( '[%s] => %s', $key, $value ); |
|
51
|
|
|
}, array_keys( $templates ), $templates ); |
|
52
|
|
|
|
|
53
|
|
|
$this->printF( implode( "\n", $templates )); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function storeTemplatePath( $template ) |
|
58
|
|
|
{ |
|
59
|
|
|
if( is_string( $template )) { |
|
60
|
|
|
$themeName = basename( strstr( $template, '/templates/', true )); |
|
61
|
|
|
$this->templatePaths[] = $themeName . strstr( $template, '/templates/' ); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function printF() |
|
66
|
|
|
{ |
|
67
|
|
|
$args = func_num_args(); |
|
68
|
|
|
|
|
69
|
|
|
if( $args == 1 ) { |
|
70
|
|
|
printf( '<div class="print__r"><pre>%s</pre></div>', |
|
71
|
|
|
htmlspecialchars( print_r( func_get_arg(0), true ), ENT_QUOTES, 'UTF-8' ) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
else if( $args > 1 ) { |
|
75
|
|
|
echo '<div class="print__r_group">'; |
|
76
|
|
|
foreach( func_get_args() as $value ) { |
|
77
|
|
|
$this->printF( $value ); |
|
78
|
|
|
} |
|
79
|
|
|
echo '</div>'; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|