11<?php
2+
23/**
34 * Ajax Handler
45 *
56 * @author vesta, http://vestacp.com/
7+ * @author Dmitry Malishev <dima.malishev@gmail.com>
8+ * @author Dmitry Naumov-Socolov <naumov.socolov@gmail.com>
69 * @copyright vesta 2010-2011
710 */
8- class AjaxHandler
9- {
11+ class AjaxHandler {
1012
1113 static public $ instance = null ;
1214
@@ -28,14 +30,12 @@ static function getInstance($request=null)
2830 * return $this->reply($result, $data, $msg, $extra);
2931 *
3032 * @param Request $request
31- * @return mixed
33+ * @return string
3234 */
33- function dispatch ($ request )
34- {
35+ function dispatch ($ request ) {
3536 $ method = Request::parseAjaxMethod ($ request );
3637 $ inc_file = V_ROOT_DIR . 'api ' . DIRECTORY_SEPARATOR . $ method ['namespace ' ] . '.class.php ' ;
37- if (!is_readable ($ inc_file ))
38- {
38+ if (!is_readable ($ inc_file )) {
3939 throw new SystemException (Message::INVALID_METHOD );
4040 }
4141
@@ -44,24 +44,17 @@ function dispatch($request)
4444 $ space = new $ method ['namespace ' ];
4545 $ method = $ method ['function ' ] . 'Execute ' ;
4646
47- if (!method_exists ($ space , $ method ))
48- {
47+ if (!method_exists ($ space , $ method )) {
4948 throw new SystemException (Message::INVALID_METHOD );
5049 }
5150
5251 return $ space ->$ method ($ request );
5352 }
5453
5554 /**
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
55+ * Prepare response for ajax
6256 */
63- function reply ($ result , $ data , $ message = '' , $ extra = array ())
64- {
57+ function reply ($ result , $ data , $ message = '' , $ extra = array ()) {
6558 return json_encode (array ('result ' => $ result ,
6659 'data ' => $ data ,
6760 'message ' => $ message ,
@@ -70,56 +63,32 @@ function reply($result, $data, $message = '', $extra = array())
7063 ));
7164 }
7265
73- /**
74- * TODO: delete this method
75- * @deprecated
76- */
77- static function makeReply ($ reply )
78- {
66+ static function makeReply ($ reply ) {
7967 print $ reply ;
8068 }
8169
8270 //
8371 // Error handlers
8472 //
8573
86- /**
87- * Generate general error
88- * @param Exception $error
89- */
90- static function generalError ($ error )
91- {
74+ static function generalError ($ error ) {
9275 self ::renderGlobalError (Message::ERROR , Message::GENERAL_ERROR , $ error );
9376 }
9477
95- /**
96- * Generate protection error
97- * @param Exception $error
98- */
99- static function protectionError ($ error )
100- {
78+ static function protectionError ($ error ) {
10179 self ::renderGlobalError (Message::ERROR , Message::PROTECTION_ERROR , $ error );
10280 }
10381
104- /**
105- * Generate system error
106- * @param Exception $error
107- */
108- static function systemError ($ error )
109- {
82+ static function systemError ($ error ) {
11083 self ::renderGlobalError (Message::ERROR , Message::SYSTEM_ERROR , $ error );
11184 }
11285
113- /**
114- * Prepare and render the error
115- * @param Exception $error
116- */
117- static function renderGlobalError ($ type , $ message , $ error )
118- {
119- $ trace = $ error ->getTrace ();
86+ static function renderGlobalError ($ type , $ message , $ error ) {
87+ /*$trace = $error->getTrace();
12088 AjaxHandler::makeReply(
121- AjaxHandler::getInstance ()->reply (false , $ type , $ message . ': ' . $ error ->getMessage (), $ trace [0 ]['file ' ] . ' / ' . $ trace [0 ]['line ' ])
122- );
89+ AjaxHandler::getInstance()->reply(false, $type, $message . ': ' . $error->getMessage(), $trace[0]['file'] . ' / ' . $trace[0]['line'])
90+ );*/
91+ print $ message ;
12392 }
12493
12594}
0 commit comments