Skip to content

Commit c11a9b3

Browse files
committed
PHP code formatted + made more readable
1 parent 4301323 commit c11a9b3

18 files changed

+2409
-1972
lines changed

web/dispatch.php

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,6 @@
11
<?php
22

3-
function error_dumper($errno, $errstr, $errfile, $errline)
4-
{
5-
if (!(error_reporting() & $errno)) {
6-
return;
7-
}
8-
9-
$log = fopen('/tmp/vesta.php.log', 'a+');
10-
11-
switch ($errno) {
12-
case E_USER_ERROR:
13-
$o = "ERROR: [$errno] $errstr\n";
14-
$o.= " Fatal error on line $errline in file $errfile";
15-
$o.= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")\n";
16-
$o.= "Aborting...\n";
17-
fwrite($log, $o);
18-
fclose($log);
19-
exit(1);
20-
break;
3+
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vesta/core/utils/error_logger.php'
4+
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vesta/app.init.php';
215

22-
case E_USER_WARNING:
23-
$o = "WARNING: [$errno] $errstr\n";
24-
fwrite($log, $o);
25-
fclose($log);
26-
break;
27-
28-
case E_USER_NOTICE:
29-
$o = "NOTICE: [$errno] $errstr\n";
30-
fwrite($log, $o);
31-
fclose($log);
32-
break;
33-
34-
default:
35-
$o = "Unknown error type: [$errno] $errstr\n";
36-
fwrite($log, $o);
37-
fclose($log);
38-
break;
39-
}
40-
41-
/* Don't execute PHP internal error handler */
42-
return true;
43-
}
44-
45-
set_error_handler('error_dumper');
46-
47-
require dirname(__FILE__).DIRECTORY_SEPARATOR.'vesta/app.init.php';
48-
49-
?>
6+
?>

web/vesta/api/AjaxHandler.php

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
2-
32
/**
43
* Ajax Handler
54
*
65
* @author vesta, http://vestacp.com/
7-
* @copyright vesta 2010
6+
* @copyright vesta 2010-2011
87
*/
9-
class AjaxHandler {
8+
class AjaxHandler
9+
{
1010

1111
static public $instance = null;
1212

@@ -16,23 +16,26 @@ class AjaxHandler {
1616
/**
1717
* Grab current instance or create it
1818
*
19-
* @return <type>
19+
* @return AjaxHandler
2020
*/
21-
static function getInstance($request=null) {
21+
static function getInstance($request=null)
22+
{
2223
return null == self::$instance ? self::$instance = new self() : self::$instance;
2324
}
2425

2526
/**
2627
* Called functions should reply in the following way
2728
* return $this->reply($result, $data, $msg, $extra);
2829
*
29-
* @param type $request
30-
* @return type
30+
* @param Request $request
31+
* @return mixed
3132
*/
32-
function dispatch($request) {
33+
function dispatch($request)
34+
{
3335
$method = Request::parseAjaxMethod($request);
3436
$inc_file = V_ROOT_DIR . 'api' . DIRECTORY_SEPARATOR . $method['namespace'] . '.class.php';
35-
if (!is_readable($inc_file)) {
37+
if (!is_readable($inc_file))
38+
{
3639
throw new SystemException(Message::INVALID_METHOD);
3740
}
3841

@@ -41,14 +44,24 @@ function dispatch($request) {
4144
$space = new $method['namespace'];
4245
$method = $method['function'] . 'Execute';
4346

44-
if (!method_exists($space, $method)) {
47+
if (!method_exists($space, $method))
48+
{
4549
throw new SystemException(Message::INVALID_METHOD);
4650
}
4751

4852
return $space->$method($request);
4953
}
5054

51-
function reply($result, $data, $message = '', $extra = array()) {
55+
/**
56+
* Prepare the result of method execution into ajax-readable format
57+
*
58+
* @param boolean $result - result of method execution
59+
* @param array $data - data to be replied
60+
* @param string $message - replied message
61+
* @param array $extra - extra data
62+
*/
63+
function reply($result, $data, $message = '', $extra = array())
64+
{
5265
return json_encode(array('result' => $result,
5366
'data' => $data,
5467
'message' => $message,
@@ -57,30 +70,55 @@ function reply($result, $data, $message = '', $extra = array()) {
5770
));
5871
}
5972

60-
static function makeReply($reply) {
73+
/**
74+
* TODO: delete this method
75+
* @deprecated
76+
*/
77+
static function makeReply($reply)
78+
{
6179
print $reply;
6280
}
6381

6482
//
6583
// Error handlers
6684
//
6785

68-
static function generalError($error) {
86+
/**
87+
* Generate general error
88+
* @param Exception $error
89+
*/
90+
static function generalError($error)
91+
{
6992
self::renderGlobalError(Message::ERROR, Message::GENERAL_ERROR, $error);
7093
}
7194

72-
static function protectionError($error) {
95+
/**
96+
* Generate protection error
97+
* @param Exception $error
98+
*/
99+
static function protectionError($error)
100+
{
73101
self::renderGlobalError(Message::ERROR, Message::PROTECTION_ERROR, $error);
74102
}
75103

76-
static function systemError($error) {
104+
/**
105+
* Generate system error
106+
* @param Exception $error
107+
*/
108+
static function systemError($error)
109+
{
77110
self::renderGlobalError(Message::ERROR, Message::SYSTEM_ERROR, $error);
78111
}
79112

80-
static function renderGlobalError($type, $message, $error) {
113+
/**
114+
* Prepare and render the error
115+
* @param Exception $error
116+
*/
117+
static function renderGlobalError($type, $message, $error)
118+
{
81119
$trace = $error->getTrace();
82120
AjaxHandler::makeReply(
83-
AjaxHandler::getInstance()->reply(false, $type, $message . ': ' . $error->getMessage(), $trace[0]['file'] . ' / ' . $trace[0]['line'])
121+
AjaxHandler::getInstance()->reply(false, $type, $message . ': ' . $error->getMessage(), $trace[0]['file'] . ' / ' . $trace[0]['line'])
84122
);
85123
}
86124

0 commit comments

Comments
 (0)