/var/www/hkosl.com/imusiccircle/webadmin/libraies/php-console/php-console/src/PhpConsole/Helper.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
<?php

namespace PhpConsole {

    
/**
     * Makes more easy access to debug dispatcher method.
     *
     * Usage:
     * 1. Call \PhpConsole\Helper::register();
     * 2. Call PC::debug($sql, 'db') or PC::db($sql)
     *
     * It will be the same as calling Handler::getInstance()->debug($var, 'db')
     *
     * @package PhpConsole
     * @version 3.1
     * @link http://php-console.com
     * @author Sergey Barbushin http://linkedin.com/in/barbushin
     * @copyright © Sergey Barbushin, 2011-2013. All rights reserved.
     * @license http://www.opensource.org/licenses/BSD-3-Clause "The BSD 3-Clause License"
     */
    
class Helper {

        
/** @var Connector|null */
        
private static $connector;
        
/** @var Handler|null */
        
private static $handler;
        
/** @var  bool */
        
protected static $isActive;

        private function 
__construct() {
        }

        
/**
         * This method must be called to make class "PC" available
         * @param Connector|null $connector
         * @param Handler|null $handler
         * @throws \Exception
         * @return Connector
         */
        
public static function register(Connector $connector nullHandler $handler null) {
            if(static::
$connector) {
                throw new \
Exception('Helper already registered');
            }
            
self::$handler $handler;
            
self::$connector $connector ? : Connector::getInstance();
            
self::$isActive self::$connector->isActiveClient();
            return 
self::$connector;
        }

        
/**
         * Check if method Helper::register() was called before
         * @return bool
         */
        
public static function isRegistered() {
            return isset(
self::$connector);
        }

        
/**
         * Get actual helper connector instance
         * @return Connector
         * @throws \Exception
         */
        
public static function getConnector() {
            if(!
self::$connector) {
                throw new \
Exception('Helper is not registered. Call ' get_called_class() . '::register()');
            }
            return 
self::$connector;
        }

        
/**
         * Get actual handler instance
         * @return Handler
         * @throws \Exception
         */
        
public static function getHandler() {
            if(!
self::$connector) {
                throw new \
Exception('Helper is not registered. Call ' get_called_class() . '::register()');
            }
            if(!
self::$handler) {
                
self::$handler Handler::getInstance();
            }
            return 
self::$handler;
        }

        
/**
         * Analog of Handler::getInstance()->debug(...) method
         * @param mixed $data
         * @param string|null $tags Tags separated by dot, e.g. "low.db.billing"
         * @param int|array $ignoreTraceCalls Ignore tracing classes by name prefix `array('PhpConsole')` or fixed number of calls to ignore
         */
        
public static function debug($data$tags null$ignoreTraceCalls 0) {
            if(
self::$isActive) {
                
self::$connector->getDebugDispatcher()->dispatchDebug($data$tagsis_numeric($ignoreTraceCalls) ? $ignoreTraceCalls $ignoreTraceCalls);
            }
        }

        
/**
         * Short access to analog of Handler::getInstance()->debug(...) method
         * You can access it like PC::tagName($debugData, $additionalTags = null)
         * @param string $tags
         * @param $args
         */
        
public static function __callStatic($tags$args) {
            if(isset(
$args[1])) {
                
$tags .= '.' $args[1];
            }
            static::
debug(isset($args[0]) ? $args[0] : null$tags1);
        }
    }
}

namespace {
    if(!
class_exists('PC'false)) {
        
/**
         * Helper short class name in global namespace
         */
        
class PC extends \PhpConsole\Helper {

        }
    }
}