Skip to content

Commit c08f85b

Browse files
committed
readme and phpdocs
1 parent 061c328 commit c08f85b

2 files changed

Lines changed: 75 additions & 13 deletions

File tree

Readme.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
1-
ErrorHandler
1+
ErrorHandler
2+
============
3+
4+
Error handling php. Can use any logger psr-3 for logging errors.
5+
6+
Installation
7+
------------
8+
```
9+
composer require dmitry-suffi/error-handler
10+
```
11+
12+
connection example
13+
------------------
14+
15+
```php
16+
17+
$handler = new \suffi\ErrorHandler\ErrorHandler();
18+
19+
set_error_handler([$handler, 'errorHandler']);
20+
set_exception_handler([$handler, 'exceptionHandler']);
21+
22+
```
23+
24+
Setting
25+
-------
26+
27+
Debug mode. Displays error details.
28+
```php
29+
30+
$handler->debug = true;
31+
32+
```
33+
34+
Error Logging. Can use any logger psr-3 for logging errors.
35+
```php
36+
37+
$handler->writeLog = true;
38+
39+
$handler->logger = $logger;
40+
41+
```
42+
43+
Writing to the log information
44+
```php
45+
46+
$handler->$debugLog = true;
47+
48+
```
49+
50+
When you inherit from the class, you can change the way display messages to the user fault conditioning.
51+
```php
52+
//Page with an error message
53+
protected function htmlError(string $errstr)
54+
{
55+
return $errstr;
56+
}
57+
58+
//Report an error for ajax-request
59+
protected function jsonError(string $errstr)
60+
{
61+
return json_encode(['error' => $errstr]);
62+
}
63+
```

src/ErrorHandler.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ErrorHandler
3838
public $debugLog = false;
3939

4040
/**
41-
* Метод перехвата ошибок
41+
* Method error trapping
4242
* @param int $errno
4343
* @param string $errstr
4444
* @param string $errfile
@@ -51,7 +51,7 @@ public function errorHandler(int $errno, string $errstr, string $errfile = '', i
5151
}
5252

5353
/**
54-
* Метод перехвата исключений
54+
* Exceptions intercept method
5555
* @param \Throwable $ex
5656
*/
5757
public function exceptionHandler(\Throwable $ex)
@@ -60,7 +60,7 @@ public function exceptionHandler(\Throwable $ex)
6060
}
6161

6262
/**
63-
* Обработка исключений
63+
* Exception Handling
6464
* @param \Throwable $ex
6565
*/
6666
protected function handler(\Throwable $ex)
@@ -83,7 +83,7 @@ protected function handler(\Throwable $ex)
8383
}
8484

8585
/**
86-
* Определение по типу
86+
* Determination of type
8787
* @param int $errno
8888
* @return bool
8989
*/
@@ -114,7 +114,7 @@ protected function isError(int $errno):bool
114114
}
115115

116116
/**
117-
* Определение типа сообщения в логе по типу ошибки
117+
* Determining the type of message in the log for the error type
118118
* @param int $errno
119119
* @return bool
120120
*/
@@ -148,7 +148,7 @@ protected function getLogLevel(int $errno):bool
148148
}
149149

150150
/**
151-
* Выбрасывает 500й статус и текст с ошибкой
151+
* Throws 500y status and the text of the error
152152
* @param string $errstr
153153
*/
154154
protected function page500(string $errstr)
@@ -169,7 +169,7 @@ protected function page500(string $errstr)
169169
}
170170

171171
/**
172-
* Парсинг шаблона
172+
* Parsing template
173173
* @param \Throwable $ex
174174
* @param string $code
175175
* @return mixed
@@ -190,7 +190,7 @@ protected function parseDebug(\Throwable $ex, $code = '')
190190
}
191191

192192
/**
193-
* Добавление глобальных переменных в строку
193+
* Adding global variables in a row
194194
* @param $fullMessage
195195
* @return string
196196
*/
@@ -232,7 +232,7 @@ protected function addGlobals($fullMessage)
232232
}
233233

234234
/**
235-
* Сообщение об ошибке в html
235+
* Error message in html
236236
* @param string $errstr
237237
* @return string
238238
*/
@@ -249,7 +249,7 @@ protected function htmlError(string $errstr)
249249
}
250250

251251
/**
252-
* Сообщение об ошибке в json
252+
* Error message in json
253253
* @param string $errstr
254254
* @return string
255255
*/
@@ -259,7 +259,7 @@ protected function jsonError(string $errstr)
259259
}
260260

261261
/**
262-
* Запись в логи об ошибке
262+
* Record error logs
263263
* @param \Throwable $ex
264264
*/
265265
protected function log(\Throwable $ex)
@@ -275,7 +275,7 @@ protected function log(\Throwable $ex)
275275
}
276276

277277
/**
278-
* Информация об ошибке
278+
* Error Information
279279
* @param \Throwable $ex
280280
*/
281281
protected function debugError(\Throwable $ex)

0 commit comments

Comments
 (0)