Completed
Push — develop ( 0f7a5c...505371 )
by Paul
02:14
created

Development::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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