コード例 #1
0
 public function beforeException(Event $event, MvcDispatcher $dispatcher, \Exception $exception)
 {
     if ($exception instanceof DispatcherException) {
         switch ($exception->getCode()) {
             case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
             case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                 HttpUtil::redirect('/errors/show404');
                 return false;
         }
     }
     LoggerUtil::error($exception->getMessage());
     HttpUtil::redirect('/errors/show500');
     return false;
 }
コード例 #2
0
 public function run($name, $args)
 {
     $lastSeparator = strrpos($name, '_');
     $rpcArgs = array('service' => substr($name, 0, $lastSeparator), 'method' => substr($name, $lastSeparator + 1), 'params' => $args);
     try {
         LoggerUtil::info('RPC CALL: ' . json_encode($rpcArgs, JSON_UNESCAPED_UNICODE));
         $serviceName = $this->getServiceName($rpcArgs['service'], false);
         $service = new $serviceName();
         $methodName = $rpcArgs['method'];
         if (!method_exists($service, $methodName)) {
             throw new \Exception(get_lang('METHOD_NOT_FOUND', $methodName));
         }
         $result = call_user_func_array(array($service, $methodName), $rpcArgs['params']);
         LoggerUtil::info('RPC SUCC: ' . json_encode($result, JSON_UNESCAPED_UNICODE));
         return $result;
     } catch (\Exception $e) {
         LoggerUtil::error('RPC FAIL: ' . $e->getMessage());
         return data_pack(get_code('REMOTE_RPC_FAIL'), $e->getMessage());
     }
 }
コード例 #3
0
ファイル: BaseModel.php プロジェクト: wanggeopens/own-libs
 /**
  * 执行原生的查询sql
  * @params string $sql    查询的sql
  * @params array $params  查询的参数
  * @params bool  $read  是否是读实例
  * @return false or array 执行失败返回false, 成功返回数组
  */
 public function execSelect($sql, $params = null)
 {
     try {
         $connect = $this->getReadConnection();
         $result = $connect->query($sql, $params);
         if (false === $result) {
             LoggerUtil::error($connect->getErrorInfo());
             return false;
         }
         $result = new \Phalcon\Mvc\Model\Resultset\Simple(null, $this, $result);
         return $result->toArray();
     } catch (\Exception $e) {
         LoggerUtil::error($e->getMessage());
         return false;
     }
 }
コード例 #4
0
ファイル: index.php プロジェクト: wanggeopens/own-libs
<?php

use App\Config\ServiceConfig;
use App\Library\AppInit;
use App\Library\HttpUtil;
use App\Library\LoggerUtil;
//定义项目的根目录
define('IS_CLI_APP', false);
define('ROOT_PATH', dirname(__DIR__));
//引入自定义函数
require ROOT_PATH . '/app/library/functions.php';
//常量定义
init_app_constant();
//引入自动加载
init_app_autoload();
//初始化容器
init_app_di();
//注册服务
ServiceConfig::register();
//初始化的一系列操作
AppInit::initContext();
//执行请求
try {
    run_cgi_application();
} catch (\Exception $e) {
    LoggerUtil::error($e->getMessage());
    HttpUtil::redirect('/errors/show500');
}