public function outputJs($key) { $config = $this->config; $version = $config->assetVersion; $assetJs = $config->asset->js; if (isset($assetJs->{$key})) { $jsUrl = HttpUtil::urlAppendParams($assetJs->{$key}, array($config->versionParam => $config->assetVersion)); return sprintf('<script src="%s"></script>' . PHP_EOL, $jsUrl); } }
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; }
<?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'); }
private static function logReqInfo() { $data = array('ip' => HttpUtil::getClientIp(), 'host' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'uri' => $_SERVER['REQUEST_URI'], 'query' => $_SERVER['QUERY_STRING'], 'method' => $_SERVER['REQUEST_METHOD'], 'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'cookie' => $_COOKIE, 'params' => $_REQUEST); LoggerUtil::info(json_encode($data, JSON_UNESCAPED_UNICODE)); }
public function errorBackUrl() { $refer = HttpUtil::getRefererUrl(); return empty($refer) ? HttpUtil::getIndexUrl() : $refer; }