public function callback($data) { try { $this->verifyCallbackParameters($data); $order = $this->getCallbackOrder(fnGet($data, 'order_id')); $this->verifyCallbackSign($order, $data, fnGet($data, 'sign')); $status = fnGet($data, 'status'); if ($status == 'complete') { if ($order->canComplete()) { $this->verifyCallbackAmount($order, fnGet($data, 'amount')); $order->complete('Test Callback'); $order->save(); } return Result::create(['order' => $order, 'response' => 'OK']); } $failureMessage = fnGet($data, 'failure_message'); if ($order->canFail()) { $order->fail($failureMessage); $order->save(); } return Result::create(['error' => $failureMessage, 'response' => 'OK']); } catch (CallbackException $e) { return Result::create(['error' => $e, 'response' => 'FAILED']); } catch (Exception $e) { Log::exception($e); return Result::create(['error' => $e, 'response' => 'FAILED']); } }
function exceptionHandler(Exception $exception) { profilerStop(); Log::exception($exception); if ($exception instanceof HttpException) { $response = $exception->toResponse(); $response->send(); return; } sendHttpStatus(500); header('content-type: application/json'); echo json_encode(['error_code' => 500, 'error_msg' => 'Server down, please check log!']); }
/** * @param string $uri * @param string $method * @return CsrfException|NotFoundException|Response */ protected function dispatch($uri, $method = 'GET') { $_SERVER['REQUEST_METHOD'] = $method; $router = $this->getRouter(); $router::staticReset(); Cookies::reset(); $this->getView()->reset(); try { return $router->dispatch($uri); } catch (Exception $e) { Log::exception($e); return $e; } }
protected function getSsoUserData($input) { try { $site = SsoSite::getSiteDataByReturnUrl(fnGet($input, 'notifyUrl')); $initToken = fnGet($input, 'initToken'); $initTime = fnGet($input, 'initTime'); if (!$this->checkInitToken($initTime, $initToken, $site)) { return ['error' => __('Invalid SSO init token')]; } if (!($user = Auth::getUser())) { return ['error' => false, 'user_data' => ['uid' => null]]; } $ssoData = ['error' => false, 'user_data' => ['uid' => $user->getId(), 'username' => $user->getUsername(), 'email' => $user->getEmail(), 'avatar' => $user->getAvatar()], 'user' => $user, 'site' => $site]; return $ssoData; } catch (Exception $e) { Log::exception($e); return ['error' => __('Other error %code% - %time%', ['code' => $e->getCode(), 'time' => date(DateTime::MYSQL_DATETIME)])]; } }
public function getContent($basePath = null) { if ($this->content === null) { if (ResourceTrait::$runningUnitTest) { Log::debug(sprintf('Asset path: [%s]', $this->_path)); } try { if ($this->_local) { $this->content = parent::getContent($basePath); } else { $path = $this->_path; substr($this->_path, 0, 2) == '//' and $path = 'http:' . $path; $this->content = file_get_contents($path, false, stream_context_create(['http' => ['method' => 'GET', 'timeout' => 1]])); } } catch (Exception $e) { Log::exception($e); $this->content = ''; } } return $this->content; }
public function callback($data) { try { $this->verifyCallbackParameters($data); $this->verifyCallbackSign(null, $data, fnGet($data, 'sign')); $order = $this->getCallbackOrder(fnGet($data, 'out_trade_no')); $status = fnGet($data, 'trade_status'); // Processing if ($status == 'WAIT_BUYER_PAY') { if ($order->canConfirm()) { $order->confirm(__('Alipay callback status %status%', ['status' => $status])); $order->save(); } return Result::create(['order' => $order, 'response' => 'success']); } // Success if ($status == 'TRADE_FINISHED' || $status == 'TRADE_SUCCESS') { if ($order->canComplete()) { $this->verifyCallbackAmount($order, fnGet($data, 'total_fee')); $order->complete('Test Callback'); $order->save(); } return Result::create(['order' => $order, 'response' => 'success']); } // Failure if ($order->canFail()) { $order->fail(__('Alipay callback status %status%', ['status' => $status])); $order->save(); } return Result::create(['order' => $order, 'response' => 'success']); } catch (CallbackException $e) { return Result::create(['error' => $e, 'response' => 'FAILED']); } catch (Exception $e) { Log::exception($e); return Result::create(['error' => $e, 'response' => 'FAILED']); } // @codeCoverageIgnoreEnd }
protected function revertMigration($filename) { $db = $this->db; $db->begin(); $file = migrationPath($filename); try { $this->logAndShowInfo(sprintf('Start reverting migration "%s"', $filename)); $migration = (include $file); if (isset($migration['down']) && is_callable($migration['down'])) { call_user_func($migration['down'], $db, $this); } $this->migrationExecuted($filename, false); $db->commit(); Db::clearMetadata(); $this->logAndShowInfo(sprintf('Finish reverting migration "%s"', $filename)); } catch (Exception $e) { $db->rollback(); Log::exception($e); $this->error(sprintf('Error when reverting migration "%s"', $filename)); $this->error($e->getMessage()); } // @codeCoverageIgnoreEnd }
public static function dispatch($uri = null) { try { static::$router === null and static::$router = static::$di->getShared('router'); $router = static::$router; // @codeCoverageIgnoreStart if (!$uri && $router->_sitePathLength && $router->_uriSource == self::URI_SOURCE_GET_URL) { list($uri) = explode('?', $_SERVER['REQUEST_URI']); $uri = str_replace(basename($_SERVER['SCRIPT_FILENAME']), '', $uri); if (substr($uri, 0, $router->_sitePathLength) == $router->_sitePathPrefix) { $uri = substr($uri, $router->_sitePathLength); } } // @codeCoverageIgnoreEnd Events::fire('router:before_dispatch', $router, ['uri' => $uri]); $router->handle($uri); $route = $router->getMatchedRoute() or static::throw404Exception(); static::$disableSession or Session::start(); static::$disableCsrfCheck or static::checkCsrfToken(); if (($controllerClass = $router->getControllerName()) instanceof Closure) { $response = $controllerClass(); if (!$response instanceof Response) { /* @var Response $realResponse */ $realResponse = static::$di->getShared('response'); $realResponse->setContent($response); $response = $realResponse; } } else { /* @var Controller $controller */ $controller = new $controllerClass(); method_exists($controller, 'initialize') and $controller->initialize(); method_exists($controller, $method = $router->getActionName()) or static::throw404Exception(); $controller->{$method}(); $response = $controller->response; } Events::fire('router:after_dispatch', $router, ['response' => $response]); Session::end(); return $response; } catch (HttpException $e) { Log::exception($e); return static::$runningUnitTest ? $e : $e->toResponse(); } }
public function render($controllerName, $actionName, $params = null) { try { $this->start(); $result = parent::render($controllerName, $actionName, $params); $this->finish(); $this->response->setContent($this->getContent()); return $result; } catch (ViewException $e) { Log::exception($e); return false; } catch (Exception $e) { throw $e; } // @codeCoverageIgnoreEnd }
protected function throwCallbackException($message, $code) { $e = new CallbackException($message, $code); Log::exception($e); throw $e; }
public function start($dryRun = false) { try { $dryRun or Log::debug('Starting...'); return parent::start($dryRun); } catch (Exception $e) { Log::exception($e); } return false; }
protected function runMigration() { $db = $this->db; $migrated = false; foreach (glob(migrationPath('*.php')) as $file) { $filename = basename($file); if ($this->migrationExecuted($filename)) { continue; } $migrated = true; $this->logAndShowInfo(sprintf('Start migration "%s"', $filename)); $db->begin(); try { $migration = (include $file); if (isset($migration['up']) && is_callable($migration['up'])) { call_user_func($migration['up'], $db, $this); } $this->migrationExecuted($filename, true); $db->commit(); } catch (Exception $e) { $db->rollback(); Log::exception($e); $this->error(sprintf('Error in migration "%s"', $filename)); $this->error($e->getMessage()); return; } // @codeCoverageIgnoreEnd $this->logAndShowInfo(sprintf('Finish migration "%s"', $filename)); } if ($migrated) { Db::clearMetadata(); } else { $this->info('Nothing to be migrated.'); } // @codeCoverageIgnoreEnd }