@@ -45,7 +45,7 @@ |
||
45 | 45 | */ |
46 | 46 | public function pop($key) { |
47 | 47 | $data = $this->get($key); |
48 | - if($data) { |
|
48 | + if ($data) { |
|
49 | 49 | $this->delete($key); |
50 | 50 | } |
51 | 51 | return $data; |
@@ -20,7 +20,7 @@ |
||
20 | 20 | |
21 | 21 | public function __construct($host = 'localhost', $port = 11211) { |
22 | 22 | $this->memcache = new \Memcache(); |
23 | - if(!$this->memcache->connect($host, $port)) { |
|
23 | + if (!$this->memcache->connect($host, $port)) { |
|
24 | 24 | throw new \Exception('Unable to connect to Memcache server'); |
25 | 25 | } |
26 | 26 | } |
@@ -21,8 +21,8 @@ |
||
21 | 21 | * @param bool $autoStart Start session if it's not started |
22 | 22 | */ |
23 | 23 | public function __construct($sessionKey = '__PHP_Console_postponed', $autoStart = true) { |
24 | - if($autoStart && (defined('PHP_SESSION_ACTIVE') ? session_status() != PHP_SESSION_ACTIVE : !session_id()) && !headers_sent()) { |
|
25 | - session_start(); |
|
24 | + if($autoStart && (defined('PHP_SESSION_ACTIVE') ? session_status() != PHP_SESSION_ACTIVE : !session_id()) && !headers_sent()) { |
|
25 | + session_start(); |
|
26 | 26 | } |
27 | 27 | register_shutdown_function('session_write_close'); // force saving session data if session handler is overridden |
28 | 28 | $this->sessionKey = $sessionKey; |
@@ -21,7 +21,7 @@ |
||
21 | 21 | * @param bool $autoStart Start session if it's not started |
22 | 22 | */ |
23 | 23 | public function __construct($sessionKey = '__PHP_Console_postponed', $autoStart = true) { |
24 | - if($autoStart && (defined('PHP_SESSION_ACTIVE') ? session_status() != PHP_SESSION_ACTIVE : !session_id()) && !headers_sent()) { |
|
24 | + if ($autoStart && (defined('PHP_SESSION_ACTIVE') ? session_status() != PHP_SESSION_ACTIVE : !session_id()) && !headers_sent()) { |
|
25 | 25 | session_start(); |
26 | 26 | } |
27 | 27 | register_shutdown_function('session_write_close'); // force saving session data if session handler is overridden |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | * @throws \Exception |
24 | 24 | */ |
25 | 25 | public function __construct($filePath, $validatePathNotUnderDocRoot = true) { |
26 | - if(!file_exists($filePath)) { |
|
27 | - if(file_put_contents($filePath, '') === false) { |
|
26 | + if (!file_exists($filePath)) { |
|
27 | + if (file_put_contents($filePath, '') === false) { |
|
28 | 28 | throw new \Exception('Unable to write file ' . $filePath); |
29 | 29 | } |
30 | 30 | } |
31 | 31 | $this->filePath = realpath($filePath); |
32 | 32 | |
33 | - if($validatePathNotUnderDocRoot && $this->isPathUnderDocRoot()) { |
|
33 | + if ($validatePathNotUnderDocRoot && $this->isPathUnderDocRoot()) { |
|
34 | 34 | throw new \Exception('Path ' . $this->filePath . ' is under DOCUMENT_ROOT. It\'s insecure!'); |
35 | 35 | } |
36 | 36 | } |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | |
42 | 42 | protected function initFileHandler() { |
43 | 43 | $this->fileHandler = fopen($this->filePath, 'a+b'); |
44 | - if(!$this->fileHandler) { |
|
44 | + if (!$this->fileHandler) { |
|
45 | 45 | throw new \Exception('Unable to read/write file ' . $this->filePath); |
46 | 46 | } |
47 | - while(!flock($this->fileHandler, LOCK_EX | LOCK_NB)) { |
|
47 | + while (!flock($this->fileHandler, LOCK_EX | LOCK_NB)) { |
|
48 | 48 | usleep(10000); |
49 | 49 | } |
50 | 50 | fseek($this->fileHandler, 0); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @return array |
56 | 56 | */ |
57 | 57 | protected function getKeysData() { |
58 | - return json_decode(fgets($this->fileHandler), true) ? : array(); |
|
58 | + return json_decode(fgets($this->fileHandler), true) ?: array(); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | protected function closeFileHandler() { |
70 | - if($this->fileHandler) { |
|
70 | + if ($this->fileHandler) { |
|
71 | 71 | flock($this->fileHandler, LOCK_UN); |
72 | 72 | fclose($this->fileHandler); |
73 | 73 | $this->fileHandler = null; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function pop($key) { |
36 | 36 | $keysData = $this->getKeysData(); |
37 | - if(isset($keysData[$key])) { |
|
37 | + if (isset($keysData[$key])) { |
|
38 | 38 | $keyData = $keysData[$key]['data']; |
39 | 39 | unset($keysData[$key]); |
40 | 40 | $this->saveKeysData($keysData); |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected function clearExpiredKeys(array &$keysData) { |
65 | 65 | $expireTime = time() - $this->keyLifetime; |
66 | - foreach($keysData as $key => $item) { |
|
67 | - if($item['time'] < $expireTime) { |
|
66 | + foreach ($keysData as $key => $item) { |
|
67 | + if ($item['time'] < $expireTime) { |
|
68 | 68 | unset($keysData[$key]); |
69 | 69 | } |
70 | 70 | } |
@@ -64,33 +64,33 @@ discard block |
||
64 | 64 | $ignoreByNumber = is_numeric($ignoreTraceCalls) ? $ignoreTraceCalls : 0; |
65 | 65 | $ignoreByClassPrefixes = is_array($ignoreTraceCalls) ? array_merge($ignoreTraceCalls, array(__NAMESPACE__)) : null; |
66 | 66 | |
67 | - foreach($trace as $i => $call) { |
|
68 | - if(!$file && $i == $ignoreTraceCalls && isset($call['file'])) { |
|
67 | + foreach ($trace as $i => $call) { |
|
68 | + if (!$file && $i == $ignoreTraceCalls && isset($call['file'])) { |
|
69 | 69 | $file = $call['file']; |
70 | 70 | $line = $call['line']; |
71 | 71 | } |
72 | - if($ignoreByClassPrefixes && isset($call['class'])) { |
|
73 | - foreach($ignoreByClassPrefixes as $classPrefix) { |
|
74 | - if(strpos($call['class'], $classPrefix) !== false) { |
|
72 | + if ($ignoreByClassPrefixes && isset($call['class'])) { |
|
73 | + foreach ($ignoreByClassPrefixes as $classPrefix) { |
|
74 | + if (strpos($call['class'], $classPrefix) !== false) { |
|
75 | 75 | unset($trace[$i]); |
76 | 76 | continue; |
77 | 77 | } |
78 | 78 | } |
79 | 79 | } |
80 | - if($i < $ignoreByNumber || (isset($call['file']) && $call['file'] == $file && $call['line'] == $line)) { |
|
80 | + if ($i < $ignoreByNumber || (isset($call['file']) && $call['file'] == $file && $call['line'] == $line)) { |
|
81 | 81 | unset($trace[$i]); |
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | 85 | $traceCalls = array(); |
86 | - foreach(array_reverse($trace) as $call) { |
|
86 | + foreach (array_reverse($trace) as $call) { |
|
87 | 87 | $args = array(); |
88 | - if(isset($call['args'])) { |
|
89 | - foreach($call['args'] as $arg) { |
|
90 | - if(is_object($arg)) { |
|
88 | + if (isset($call['args'])) { |
|
89 | + foreach ($call['args'] as $arg) { |
|
90 | + if (is_object($arg)) { |
|
91 | 91 | $args[] = get_class($arg); |
92 | 92 | } |
93 | - elseif(is_array($arg)) { |
|
93 | + elseif (is_array($arg)) { |
|
94 | 94 | $args[] = 'Array[' . count($arg) . ']'; |
95 | 95 | } |
96 | 96 | else { |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - if(strpos($call['function'], '{closure}')) { |
|
103 | + if (strpos($call['function'], '{closure}')) { |
|
104 | 104 | $call['function'] = '{closure}'; |
105 | 105 | } |
106 | 106 | |
107 | 107 | $traceCall = new TraceCall(); |
108 | 108 | $traceCall->call = (isset($call['class']) ? $call['class'] . $call['type'] : '') . $call['function'] . '(' . implode(', ', $args) . ')'; |
109 | - if(isset($call['file'])) { |
|
109 | + if (isset($call['file'])) { |
|
110 | 110 | $traceCall->file = $call['file']; |
111 | 111 | } |
112 | - if(isset($call['line'])) { |
|
112 | + if (isset($call['line'])) { |
|
113 | 113 | $traceCall->line = $call['line']; |
114 | 114 | } |
115 | 115 | $traceCalls[] = $traceCall; |
@@ -89,11 +89,9 @@ |
||
89 | 89 | foreach($call['args'] as $arg) { |
90 | 90 | if(is_object($arg)) { |
91 | 91 | $args[] = get_class($arg); |
92 | - } |
|
93 | - elseif(is_array($arg)) { |
|
92 | + } elseif(is_array($arg)) { |
|
94 | 93 | $args[] = 'Array[' . count($arg) . ']'; |
95 | - } |
|
96 | - else { |
|
94 | + } else { |
|
97 | 95 | $arg = var_export($arg, 1); |
98 | 96 | $args[] = strlen($arg) > 15 ? substr($arg, 0, 15) . '...\'' : $arg; |
99 | 97 | } |
@@ -61,24 +61,24 @@ discard block |
||
61 | 61 | $refQueue = array(), |
62 | 62 | $levelsQueue = array(); |
63 | 63 | |
64 | - if($rootCall) { |
|
65 | - $sizeLeft = $this->dumpSizeLimit ? : 999999999; |
|
64 | + if ($rootCall) { |
|
65 | + $sizeLeft = $this->dumpSizeLimit ?: 999999999; |
|
66 | 66 | } |
67 | 67 | |
68 | - if(is_object($data)) { |
|
69 | - if($data instanceof \Closure) { |
|
68 | + if (is_object($data)) { |
|
69 | + if ($data instanceof \Closure) { |
|
70 | 70 | $data = '(callback function)'; |
71 | 71 | return; |
72 | 72 | } |
73 | - if($rootCall) { |
|
73 | + if ($rootCall) { |
|
74 | 74 | $data = array('' => $data); |
75 | 75 | return $this->dumpVarData($data, $levelLimit + 1); |
76 | 76 | } |
77 | 77 | $objectsHashes[] = spl_object_hash($data); |
78 | 78 | $dataArray = array(); |
79 | - foreach((array)$data as $key => $value) { |
|
79 | + foreach ((array)$data as $key => $value) { |
|
80 | 80 | $nullPos = strrpos($key, chr(0)); |
81 | - if($nullPos) { |
|
81 | + if ($nullPos) { |
|
82 | 82 | $dataArray[substr($key, $nullPos + 1)] = $value; |
83 | 83 | } |
84 | 84 | else { |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | $data = $dataArray; |
89 | 89 | } |
90 | 90 | |
91 | - if(is_array($data)) { |
|
91 | + if (is_array($data)) { |
|
92 | 92 | |
93 | - if($this->detectCallbacks && count($data) == 2 && is_callable($data)) { |
|
93 | + if ($this->detectCallbacks && count($data) == 2 && is_callable($data)) { |
|
94 | 94 | list($class, $method) = $data; |
95 | 95 | $data = '(callback ' . (is_object($class) ? get_class($class) : $class) . '::' . $method . ')'; |
96 | 96 | $sizeLeft -= strlen($data) + 4; |
@@ -99,20 +99,20 @@ discard block |
||
99 | 99 | |
100 | 100 | $i = 0; |
101 | 101 | $dataArray = array(); |
102 | - foreach($data as $k => &$v) { |
|
103 | - if(($this->itemsCountLimit && $i >= $this->itemsCountLimit) || $sizeLeft <= 0) { |
|
102 | + foreach ($data as $k => &$v) { |
|
103 | + if (($this->itemsCountLimit && $i >= $this->itemsCountLimit) || $sizeLeft <= 0) { |
|
104 | 104 | break; |
105 | 105 | } |
106 | - if(is_array($v) || is_object($v)) { |
|
107 | - if($levelLimit > 1) { |
|
106 | + if (is_array($v) || is_object($v)) { |
|
107 | + if ($levelLimit > 1) { |
|
108 | 108 | $origQueue[] = $v; |
109 | - $refQueue[] =& $v; |
|
109 | + $refQueue[] = & $v; |
|
110 | 110 | $levelsQueue[] = $levelLimit; |
111 | 111 | } |
112 | - if(is_object($v) && !$v instanceof \Closure) { |
|
112 | + if (is_object($v) && !$v instanceof \Closure) { |
|
113 | 113 | $k .= ':' . get_class($v); |
114 | 114 | $hash = spl_object_hash($v); |
115 | - if(in_array($hash, $objectsHashes)) { |
|
115 | + if (in_array($hash, $objectsHashes)) { |
|
116 | 116 | $v = '*RECURSION*'; |
117 | 117 | } |
118 | 118 | else { |
@@ -129,50 +129,50 @@ discard block |
||
129 | 129 | $sizeLeft -= strlen($k) + 4; |
130 | 130 | $this->dumpVarData($v, $levelLimit - 1, false); |
131 | 131 | } |
132 | - $dataArray[$k] =& $v; |
|
132 | + $dataArray[$k] = & $v; |
|
133 | 133 | $i++; |
134 | 134 | } |
135 | 135 | |
136 | - if($i != count($data)) { |
|
136 | + if ($i != count($data)) { |
|
137 | 137 | $dataArray['...'] = '(displayed ' . $i . ' of ' . count($data) . ')'; |
138 | 138 | } |
139 | 139 | $data = $dataArray; |
140 | 140 | |
141 | - if(!$rootCall) { |
|
141 | + if (!$rootCall) { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | |
145 | 145 | do { |
146 | 146 | $origData = array_shift($origQueue); |
147 | 147 | $level = array_shift($levelsQueue); |
148 | - $refData =& $refQueue[0]; |
|
148 | + $refData = & $refQueue[0]; |
|
149 | 149 | array_shift($refQueue); |
150 | 150 | $sizeLeft += strlen($refData); |
151 | - if($refData !== '*RECURSION*') { |
|
151 | + if ($refData !== '*RECURSION*') { |
|
152 | 152 | $this->dumpVarData($origData, $level - 1, false); |
153 | 153 | $refData = $origData; |
154 | 154 | } |
155 | 155 | } |
156 | - while(count($origQueue) && $sizeLeft >= 0); |
|
156 | + while (count($origQueue) && $sizeLeft >= 0); |
|
157 | 157 | |
158 | - if($rootCall) { |
|
158 | + if ($rootCall) { |
|
159 | 159 | $levelsQueue = $origQueue = $refQueue = $objectsHashes = array(); |
160 | 160 | } |
161 | 161 | } |
162 | 162 | // scalar or resource |
163 | 163 | else { |
164 | - if(!is_scalar($data) && $data !== null) { |
|
165 | - if(is_resource($data)) { |
|
164 | + if (!is_scalar($data) && $data !== null) { |
|
165 | + if (is_resource($data)) { |
|
166 | 166 | $data = '(' . strtolower((string)$data) . ' ' . get_resource_type($data) . ')'; |
167 | 167 | $sizeLeft -= strlen($data); |
168 | 168 | return; |
169 | 169 | } |
170 | 170 | $data = var_export($data, true); |
171 | 171 | } |
172 | - if(strlen($data) > $this->itemSizeLimit) { |
|
172 | + if (strlen($data) > $this->itemSizeLimit) { |
|
173 | 173 | $data = substr($data, 0, $this->itemSizeLimit - 3) . '...'; |
174 | 174 | } |
175 | - if(strlen($data) > $sizeLeft) { |
|
175 | + if (strlen($data) > $sizeLeft) { |
|
176 | 176 | $data = substr($data, 0, $sizeLeft - 3) . '...'; |
177 | 177 | } |
178 | 178 | $sizeLeft -= strlen($data); |
@@ -80,8 +80,7 @@ discard block |
||
80 | 80 | $nullPos = strrpos($key, chr(0)); |
81 | 81 | if($nullPos) { |
82 | 82 | $dataArray[substr($key, $nullPos + 1)] = $value; |
83 | - } |
|
84 | - else { |
|
83 | + } else { |
|
85 | 84 | $dataArray[$key] = $value; |
86 | 85 | } |
87 | 86 | } |
@@ -114,18 +113,15 @@ discard block |
||
114 | 113 | $hash = spl_object_hash($v); |
115 | 114 | if(in_array($hash, $objectsHashes)) { |
116 | 115 | $v = '*RECURSION*'; |
117 | - } |
|
118 | - else { |
|
116 | + } else { |
|
119 | 117 | $v = '(object)'; |
120 | 118 | $objectsHashes[] = $hash; |
121 | 119 | } |
122 | - } |
|
123 | - else { |
|
120 | + } else { |
|
124 | 121 | $v = '(array)'; |
125 | 122 | } |
126 | 123 | $sizeLeft -= strlen($k) + strlen($v) + 8; |
127 | - } |
|
128 | - else { |
|
124 | + } else { |
|
129 | 125 | $sizeLeft -= strlen($k) + 4; |
130 | 126 | $this->dumpVarData($v, $levelLimit - 1, false); |
131 | 127 | } |
@@ -393,8 +393,7 @@ |
||
393 | 393 | } |
394 | 394 | if($isMbString) { |
395 | 395 | $string = @mb_convert_encoding($string, $toEncoding, $fromEncoding) ? : $string; |
396 | - } |
|
397 | - else { |
|
396 | + } else { |
|
398 | 397 | $string = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string) ? : $string; |
399 | 398 | } |
400 | 399 | if(!$string && $toEncoding == 'UTF-8') { |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return static |
65 | 65 | */ |
66 | 66 | public static function getInstance() { |
67 | - if(!self::$instance) { |
|
67 | + if (!self::$instance) { |
|
68 | 68 | self::$instance = new static(); |
69 | 69 | } |
70 | 70 | return self::$instance; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @throws \Exception |
78 | 78 | */ |
79 | 79 | public static function setPostponeStorage(Storage $storage) { |
80 | - if(self::$instance) { |
|
80 | + if (self::$instance) { |
|
81 | 81 | throw new \Exception(__METHOD__ . ' can be called only before ' . __CLASS__ . '::getInstance()'); |
82 | 82 | } |
83 | 83 | self::$postponeStorage = $storage; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @return Storage |
88 | 88 | */ |
89 | 89 | private function getPostponeStorage() { |
90 | - if(!self::$postponeStorage) { |
|
90 | + if (!self::$postponeStorage) { |
|
91 | 91 | self::$postponeStorage = new Storage\Session(); |
92 | 92 | } |
93 | 93 | return self::$postponeStorage; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | protected function __construct() { |
97 | 97 | $this->initConnection(); |
98 | - $this->setServerEncoding(ini_get('mbstring.internal_encoding') ? : self::CLIENT_ENCODING); |
|
98 | + $this->setServerEncoding(ini_get('mbstring.internal_encoding') ?: self::CLIENT_ENCODING); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | private function __clone() { |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | * @throws \Exception |
115 | 115 | */ |
116 | 116 | private function initConnection() { |
117 | - if($this->isCliMode()) { |
|
117 | + if ($this->isCliMode()) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
121 | 121 | $this->initServerCookie(); |
122 | 122 | $this->client = $this->initClient(); |
123 | 123 | |
124 | - if($this->client) { |
|
124 | + if ($this->client) { |
|
125 | 125 | ob_start(); |
126 | 126 | $this->isActiveClient = true; |
127 | 127 | $this->registerFlushOnShutDown(); |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | * @throws \Exception |
141 | 141 | */ |
142 | 142 | private function initClient() { |
143 | - if(isset($_COOKIE[self::CLIENT_INFO_COOKIE])) { |
|
143 | + if (isset($_COOKIE[self::CLIENT_INFO_COOKIE])) { |
|
144 | 144 | $clientData = @json_decode(base64_decode($_COOKIE[self::CLIENT_INFO_COOKIE], true), true); |
145 | - if(!$clientData) { |
|
145 | + if (!$clientData) { |
|
146 | 146 | throw new \Exception('Wrong format of response cookie data: ' . $_COOKIE[self::CLIENT_INFO_COOKIE]); |
147 | 147 | } |
148 | 148 | |
149 | 149 | $client = new Client($clientData); |
150 | - if(isset($clientData['auth'])) { |
|
150 | + if (isset($clientData['auth'])) { |
|
151 | 151 | $client->auth = new ClientAuth($clientData['auth']); |
152 | 152 | } |
153 | 153 | return $client; |
@@ -159,9 +159,9 @@ discard block |
||
159 | 159 | * @throws \Exception |
160 | 160 | */ |
161 | 161 | private function initServerCookie() { |
162 | - if(!isset($_COOKIE[self::SERVER_COOKIE]) || $_COOKIE[self::SERVER_COOKIE] != self::SERVER_PROTOCOL) { |
|
162 | + if (!isset($_COOKIE[self::SERVER_COOKIE]) || $_COOKIE[self::SERVER_COOKIE] != self::SERVER_PROTOCOL) { |
|
163 | 163 | $isSuccess = setcookie(self::SERVER_COOKIE, self::SERVER_PROTOCOL, null, '/'); |
164 | - if(!$isSuccess) { |
|
164 | + if (!$isSuccess) { |
|
165 | 165 | throw new \Exception('Unable to set PHP Console server cookie'); |
166 | 166 | } |
167 | 167 | } |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | * @param array $ipMasks Use *(star character) for "any numbers" placeholder array('192.168.*.*', '10.2.12*.*', '127.0.0.1', '2001:0:5ef5:79fb:*:*:*:*') |
196 | 196 | */ |
197 | 197 | public function setAllowedIpMasks(array $ipMasks) { |
198 | - if($this->isActiveClient()) { |
|
199 | - if(isset($_SERVER['REMOTE_ADDR'])) { |
|
198 | + if ($this->isActiveClient()) { |
|
199 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
200 | 200 | $ip = $_SERVER['REMOTE_ADDR']; |
201 | - foreach($ipMasks as $ipMask) { |
|
202 | - if(preg_match('~^' . str_replace(array('.', '*'), array('\.', '\w+'), $ipMask) . '$~i', $ip)) { |
|
201 | + foreach ($ipMasks as $ipMask) { |
|
202 | + if (preg_match('~^' . str_replace(array('.', '*'), array('\.', '\w+'), $ipMask) . '$~i', $ip)) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | 205 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @return Dumper |
213 | 213 | */ |
214 | 214 | public function getDumper() { |
215 | - if(!$this->dumper) { |
|
215 | + if (!$this->dumper) { |
|
216 | 216 | $this->dumper = new Dumper(); |
217 | 217 | } |
218 | 218 | return $this->dumper; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @return Dispatcher\Errors |
232 | 232 | */ |
233 | 233 | public function getErrorsDispatcher() { |
234 | - if(!$this->errorsDispatcher) { |
|
234 | + if (!$this->errorsDispatcher) { |
|
235 | 235 | $this->errorsDispatcher = new Dispatcher\Errors($this, $this->getDumper()); |
236 | 236 | } |
237 | 237 | return $this->errorsDispatcher; |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @return Dispatcher\Debug |
251 | 251 | */ |
252 | 252 | public function getDebugDispatcher() { |
253 | - if(!$this->debugDispatcher) { |
|
253 | + if (!$this->debugDispatcher) { |
|
254 | 254 | $this->debugDispatcher = new Dispatcher\Debug($this, $this->getDumper()); |
255 | 255 | } |
256 | 256 | return $this->debugDispatcher; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * @return Dispatcher\Evaluate |
270 | 270 | */ |
271 | 271 | public function getEvalDispatcher() { |
272 | - if(!$this->evalDispatcher) { |
|
272 | + if (!$this->evalDispatcher) { |
|
273 | 273 | $this->evalDispatcher = new Dispatcher\Evaluate($this, new EvalProvider(), $this->getDumper()); |
274 | 274 | } |
275 | 275 | return $this->evalDispatcher; |
@@ -285,32 +285,32 @@ discard block |
||
285 | 285 | * @throws \Exception |
286 | 286 | */ |
287 | 287 | public function startEvalRequestsListener($exitOnEval = true, $flushDebugMessages = true) { |
288 | - if(!$this->auth) { |
|
288 | + if (!$this->auth) { |
|
289 | 289 | throw new \Exception('Eval dispatcher is allowed only in password protected mode. See PhpConsole\Connector::getInstance()->setPassword(...)'); |
290 | 290 | } |
291 | - if($this->isEvalListenerStarted) { |
|
291 | + if ($this->isEvalListenerStarted) { |
|
292 | 292 | throw new \Exception('Eval requests listener already started'); |
293 | 293 | } |
294 | 294 | $this->isEvalListenerStarted = true; |
295 | 295 | |
296 | - if($this->isActiveClient() && $this->isAuthorized() && isset($_POST[Connector::POST_VAR_NAME]['eval'])) { |
|
296 | + if ($this->isActiveClient() && $this->isAuthorized() && isset($_POST[Connector::POST_VAR_NAME]['eval'])) { |
|
297 | 297 | $request = $_POST[Connector::POST_VAR_NAME]['eval']; |
298 | - if(!isset($request['data']) || !isset($request['signature'])) { |
|
298 | + if (!isset($request['data']) || !isset($request['signature'])) { |
|
299 | 299 | throw new \Exception('Wrong PHP Console eval request'); |
300 | 300 | } |
301 | - if($this->auth->getSignature($request['data']) !== $request['signature']) { |
|
301 | + if ($this->auth->getSignature($request['data']) !== $request['signature']) { |
|
302 | 302 | throw new \Exception('Wrong PHP Console eval request signature'); |
303 | 303 | } |
304 | - if($flushDebugMessages) { |
|
305 | - foreach($this->messages as $i => $message) { |
|
306 | - if($message instanceof DebugMessage) { |
|
304 | + if ($flushDebugMessages) { |
|
305 | + foreach ($this->messages as $i => $message) { |
|
306 | + if ($message instanceof DebugMessage) { |
|
307 | 307 | unset($this->messages[$i]); |
308 | 308 | } |
309 | 309 | } |
310 | 310 | } |
311 | 311 | $this->convertEncoding($request['data'], $this->serverEncoding, self::CLIENT_ENCODING); |
312 | 312 | $this->getEvalDispatcher()->dispatchCode($request['data']); |
313 | - if($exitOnEval) { |
|
313 | + if ($exitOnEval) { |
|
314 | 314 | exit; |
315 | 315 | } |
316 | 316 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | */ |
324 | 324 | public function setSourcesBasePath($sourcesBasePath) { |
325 | 325 | $sourcesBasePath = realpath($sourcesBasePath); |
326 | - if(!$sourcesBasePath) { |
|
326 | + if (!$sourcesBasePath) { |
|
327 | 327 | throw new \Exception('Path "' . $sourcesBasePath . '" not found'); |
328 | 328 | } |
329 | 329 | $this->sourcesBasePath = $sourcesBasePath; |
@@ -338,12 +338,12 @@ discard block |
||
338 | 338 | * @throws \Exception |
339 | 339 | */ |
340 | 340 | public function setPassword($password, $publicKeyByIp = true) { |
341 | - if($this->auth) { |
|
341 | + if ($this->auth) { |
|
342 | 342 | throw new \Exception('Password already defined'); |
343 | 343 | } |
344 | 344 | $this->convertEncoding($password, self::CLIENT_ENCODING, $this->serverEncoding); |
345 | 345 | $this->auth = new Auth($password, $publicKeyByIp); |
346 | - if($this->client) { |
|
346 | + if ($this->client) { |
|
347 | 347 | $this->isAuthorized = $this->client->auth && $this->auth->isValidAuth($this->client->auth); |
348 | 348 | } |
349 | 349 | } |
@@ -386,18 +386,18 @@ discard block |
||
386 | 386 | * @throws \Exception |
387 | 387 | */ |
388 | 388 | protected function convertEncoding(&$string, $toEncoding, $fromEncoding) { |
389 | - if($string && is_string($string) && $toEncoding != $fromEncoding) { |
|
389 | + if ($string && is_string($string) && $toEncoding != $fromEncoding) { |
|
390 | 390 | static $isMbString; |
391 | - if($isMbString === null) { |
|
391 | + if ($isMbString === null) { |
|
392 | 392 | $isMbString = extension_loaded('mbstring'); |
393 | 393 | } |
394 | - if($isMbString) { |
|
395 | - $string = @mb_convert_encoding($string, $toEncoding, $fromEncoding) ? : $string; |
|
394 | + if ($isMbString) { |
|
395 | + $string = @mb_convert_encoding($string, $toEncoding, $fromEncoding) ?: $string; |
|
396 | 396 | } |
397 | 397 | else { |
398 | - $string = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string) ? : $string; |
|
398 | + $string = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string) ?: $string; |
|
399 | 399 | } |
400 | - if(!$string && $toEncoding == 'UTF-8') { |
|
400 | + if (!$string && $toEncoding == 'UTF-8') { |
|
401 | 401 | $string = utf8_encode($string); |
402 | 402 | } |
403 | 403 | } |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | * @throws \Exception |
410 | 410 | */ |
411 | 411 | public function setHeadersLimit($bytes) { |
412 | - if($bytes < static::PHP_HEADERS_SIZE) { |
|
412 | + if ($bytes < static::PHP_HEADERS_SIZE) { |
|
413 | 413 | throw new \Exception('Headers limit cannot be less then ' . __CLASS__ . '::PHP_HEADERS_SIZE'); |
414 | 414 | } |
415 | 415 | $bytes -= static::PHP_HEADERS_SIZE; |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | * @param $encoding |
422 | 422 | */ |
423 | 423 | public function setServerEncoding($encoding) { |
424 | - if($encoding == 'utf8' || $encoding == 'utf-8') { |
|
424 | + if ($encoding == 'utf8' || $encoding == 'utf-8') { |
|
425 | 425 | $encoding = 'UTF-8'; // otherwise mb_convert_encoding() sometime fails with error(thanks to @alexborisov) |
426 | 426 | } |
427 | 427 | $this->serverEncoding = $encoding; |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * @param Message $message |
433 | 433 | */ |
434 | 434 | public function sendMessage(Message $message) { |
435 | - if($this->isActiveClient()) { |
|
435 | + if ($this->isActiveClient()) { |
|
436 | 436 | $this->messages[] = $message; |
437 | 437 | } |
438 | 438 | } |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | */ |
451 | 451 | public function onShutDown() { |
452 | 452 | $this->registeredShutDowns--; |
453 | - if(!$this->registeredShutDowns) { |
|
453 | + if (!$this->registeredShutDowns) { |
|
454 | 454 | $this->proceedResponsePackage(); |
455 | 455 | } |
456 | 456 | } |
@@ -475,19 +475,19 @@ discard block |
||
475 | 475 | * @throws \Exception |
476 | 476 | */ |
477 | 477 | private function proceedResponsePackage() { |
478 | - if($this->isActiveClient()) { |
|
478 | + if ($this->isActiveClient()) { |
|
479 | 479 | $response = new Response(); |
480 | 480 | $response->isSslOnlyMode = $this->isSslOnlyMode; |
481 | 481 | |
482 | - if(isset($_POST[self::POST_VAR_NAME]['getBackData'])) { |
|
482 | + if (isset($_POST[self::POST_VAR_NAME]['getBackData'])) { |
|
483 | 483 | $response->getBackData = $_POST[self::POST_VAR_NAME]['getBackData']; |
484 | 484 | } |
485 | 485 | |
486 | - if(!$this->isSslOnlyMode || $this->isSsl()) { |
|
487 | - if($this->auth) { |
|
486 | + if (!$this->isSslOnlyMode || $this->isSsl()) { |
|
487 | + if ($this->auth) { |
|
488 | 488 | $response->auth = $this->auth->getServerAuthStatus($this->client->auth); |
489 | 489 | } |
490 | - if(!$this->auth || $this->isAuthorized()) { |
|
490 | + if (!$this->auth || $this->isAuthorized()) { |
|
491 | 491 | $response->isLocal = isset($_SERVER['REMOTE_ADDR']) && ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1'); |
492 | 492 | $response->docRoot = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : null; |
493 | 493 | $response->sourcesBasePath = $this->sourcesBasePath; |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | |
499 | 499 | $responseData = $this->serializeResponse($response); |
500 | 500 | |
501 | - if(strlen($responseData) > $this->headersLimit || !$this->setHeaderData($responseData, self::HEADER_NAME, false)) { |
|
501 | + if (strlen($responseData) > $this->headersLimit || !$this->setHeaderData($responseData, self::HEADER_NAME, false)) { |
|
502 | 502 | $this->getPostponeStorage()->push($this->postponeResponseId, $responseData); |
503 | 503 | } |
504 | 504 | } |
@@ -515,8 +515,8 @@ discard block |
||
515 | 515 | } |
516 | 516 | |
517 | 517 | private function setHeaderData($responseData, $headerName, $throwException = true) { |
518 | - if(headers_sent($file, $line)) { |
|
519 | - if($throwException) { |
|
518 | + if (headers_sent($file, $line)) { |
|
519 | + if ($throwException) { |
|
520 | 520 | throw new \Exception('Unable to process response data, headers already sent in ' . $file . ':' . $line . '. Try to use ob_start() and don\'t use flush().'); |
521 | 521 | } |
522 | 522 | return false; |
@@ -526,14 +526,14 @@ discard block |
||
526 | 526 | } |
527 | 527 | |
528 | 528 | protected function objectToArray(&$var) { |
529 | - if(is_object($var)) { |
|
529 | + if (is_object($var)) { |
|
530 | 530 | $var = get_object_vars($var); |
531 | 531 | array_walk_recursive($var, array($this, 'objectToArray')); |
532 | 532 | } |
533 | 533 | } |
534 | 534 | |
535 | 535 | protected function serializeResponse(DataObject $response) { |
536 | - if($this->serverEncoding != self::CLIENT_ENCODING) { |
|
536 | + if ($this->serverEncoding != self::CLIENT_ENCODING) { |
|
537 | 537 | $this->objectToArray($response); |
538 | 538 | $this->convertArrayEncoding($response, self::CLIENT_ENCODING, $this->serverEncoding); |
539 | 539 | } |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | * Check if there is postponed response request and dispatch it |
545 | 545 | */ |
546 | 546 | private function listenGetPostponedResponse() { |
547 | - if(isset($_POST[self::POST_VAR_NAME]['getPostponedResponse'])) { |
|
547 | + if (isset($_POST[self::POST_VAR_NAME]['getPostponedResponse'])) { |
|
548 | 548 | header('Content-Type: application/json; charset=' . self::CLIENT_ENCODING); |
549 | 549 | echo $this->getPostponeStorage()->pop($_POST[self::POST_VAR_NAME]['getPostponedResponse']); |
550 | 550 | $this->disable(); |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | abstract class DataObject { |
557 | 557 | |
558 | 558 | public function __construct(array $properties = array()) { |
559 | - foreach($properties as $property => $value) { |
|
559 | + foreach ($properties as $property => $value) { |
|
560 | 560 | $this->$property = $value; |
561 | 561 | } |
562 | 562 | } |
@@ -71,11 +71,11 @@ |
||
71 | 71 | */ |
72 | 72 | protected function getClientUid() { |
73 | 73 | $clientUid = ''; |
74 | - if($this->publicKeyByIp) { |
|
75 | - if(isset($_SERVER['REMOTE_ADDR'])) { |
|
74 | + if ($this->publicKeyByIp) { |
|
75 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
76 | 76 | $clientUid .= $_SERVER['REMOTE_ADDR']; |
77 | 77 | } |
78 | - if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
78 | + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
79 | 79 | $clientUid .= $_SERVER['HTTP_X_FORWARDED_FOR']; |
80 | 80 | } |
81 | 81 | } |