1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpConsole { |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* There is adapter of PhpConsole v1.x to v3.x |
7
|
|
|
* It's for users that just want to migrate from PhpConsole v1 to v3 without any code changes |
8
|
|
|
* |
9
|
|
|
* Usage: |
10
|
|
|
* |
11
|
|
|
* 1. Register PhpConsole class emulator |
12
|
|
|
* |
13
|
|
|
* require_once('/path/to/src/PhpConsole/__autoload.php'); |
14
|
|
|
* \PhpConsole\OldVersionAdapter::register(); |
15
|
|
|
* |
16
|
|
|
* 2. Call PhpConsole v1.x methods as is: |
17
|
|
|
* |
18
|
|
|
* $pc = PhpConsole::getInstance(); |
19
|
|
|
* $pc->start($handleErrors = true, $handleExceptions = true, $sourceBasePath = null); |
20
|
|
|
* PhpConsole::debug('message', 'some,tags'); |
21
|
|
|
* debug('message', 'some,tags'); |
22
|
|
|
* |
23
|
|
|
* IMPORTANT: This adapter will be removed in PhpConsole > v3, so it's strongly recommended to migrate your code using original PhpConsole v3 methods |
24
|
|
|
* |
25
|
|
|
* @package PhpConsole |
26
|
|
|
* @version 3.1 |
27
|
|
|
* @link http://consle.com |
28
|
|
|
* @author Sergey Barbushin http://linkedin.com/in/barbushin |
29
|
|
|
* @copyright © Sergey Barbushin, 2011-2013. All rights reserved. |
30
|
|
|
* @license http://www.opensource.org/licenses/BSD-3-Clause "The BSD 3-Clause License" |
31
|
|
|
* @codeCoverageIgnore |
32
|
|
|
*/ |
33
|
|
|
class OldVersionAdapter { |
34
|
|
|
|
35
|
|
|
public static $callOldErrorHandler = true; |
36
|
|
|
public static $callOldExceptionsHandler = true; |
37
|
|
|
|
38
|
|
|
/** @var OldVersionAdapter|null */ |
39
|
|
|
protected static $instance; |
40
|
|
|
|
41
|
|
|
private function __construct() { |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* This method must be called just to force \PhpConsole class initialization |
46
|
|
|
* @param Connector|null $connector |
47
|
|
|
* @param Handler|null $handler |
48
|
|
|
* @throws \Exception |
49
|
|
|
* @return Connector |
50
|
|
|
*/ |
51
|
|
|
public static function register(Connector $connector = null, Handler $handler = null) { |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Start PhpConsole v1 handler |
56
|
|
|
* @param bool $handleErrors |
57
|
|
|
* @param bool $handleExceptions |
58
|
|
|
* @param null|string $sourceBasePath |
59
|
|
|
*/ |
60
|
|
|
public static function start($handleErrors = true, $handleExceptions = true, $sourceBasePath = null) { |
61
|
|
|
if(self::$instance) { |
62
|
|
|
die('PhpConsole already started'); |
63
|
|
|
} |
64
|
|
|
self::$instance = new static(); |
65
|
|
|
|
66
|
|
|
$handler = Handler::getInstance(); |
67
|
|
|
$handler->setHandleErrors($handleErrors); |
68
|
|
|
$handler->setHandleExceptions($handleExceptions); |
69
|
|
|
$handler->setCallOldHandlers(self::$callOldErrorHandler || self::$callOldExceptionsHandler); |
70
|
|
|
$handler->start(); |
71
|
|
|
|
72
|
|
|
$connector = $handler->getConnector(); |
73
|
|
|
$connector->setSourcesBasePath($sourceBasePath); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public static function getInstance() { |
77
|
|
|
if(!self::$instance) { |
78
|
|
|
throw new \Exception('PhpConsole not started'); |
79
|
|
|
} |
80
|
|
|
return self::$instance; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return Connector |
85
|
|
|
*/ |
86
|
|
|
public function getConnector() { |
87
|
|
|
return Connector::getInstance(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return Handler |
92
|
|
|
*/ |
93
|
|
|
public function getHandler() { |
94
|
|
|
return Handler::getInstance(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function handleError($code = null, $message = null, $file = null, $line = null) { |
98
|
|
|
$this->getHandler()->handleError($code, $message, $file, $line, null, 1); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function handleException($exception) { |
102
|
|
|
$this->getHandler()->handleException($exception); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public static function debug($message, $tags = 'debug') { |
106
|
|
|
Handler::getInstance()->debug($message, str_replace(',', '.', $tags), 1); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
namespace { |
112
|
|
|
|
113
|
|
|
use PhpConsole\Handler; |
114
|
|
|
use PhpConsole\OldVersionAdapter; |
115
|
|
|
|
116
|
|
|
if(!class_exists('PhpConsole', false)) { |
117
|
|
|
class PhpConsole extends OldVersionAdapter { |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if(!function_exists('debug')) { |
123
|
|
|
function debug($message, $tags = 'debug') { |
124
|
|
|
Handler::getInstance()->debug($message, $tags, 1); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.