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