1. Go to this page and download the library: Download easyswoole/easy-whoops library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
easyswoole / easy-whoops example snippets
/**
* Created by PhpStorm.
* User: yf
* Date: 2018/5/28
* Time: 下午6:33
*/
namespace EasySwoole\EasySwoole;
use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;
use EasySwoole\Whoops\Handler\CallbackHandler;
use EasySwoole\Whoops\Handler\PrettyPageHandler;
use EasySwoole\Whoops\Run;
use EasySwoole\Component\Di;
class EasySwooleEvent implements Event
{
/**
* 框架初始化
*/
public static function initialize()
{
date_default_timezone_set('Asia/Shanghai');
$whoops = new Run();
$whoops->pushHandler(new PrettyPageHandler); // 输出一个漂亮的页面
$whoops->pushHandler(new CallbackHandler(function ($exception, $inspector, $run, $handle) {
// 可以推进多个Handle 支持回调做更多后续处理
}));
$whoops->register();
// 收到请求时
Di::getInstance()->set(\EasySwoole\EasySwoole\SysConst::HTTP_GLOBAL_ON_REQUEST, function (Request $request, Response $response): bool {
// 拦截请求
Run::attachRequest($request, $response);
return true;
});
// 请求结束时
Di::getInstance()->set(\EasySwoole\EasySwoole\SysConst::HTTP_GLOBAL_AFTER_REQUEST, function (Request $request, Response $response): void {
// TODO: Implement afterAction() method.
});
}
/**
* 主服务启动前
* @param EventRegister $register
*/
public static function mainServerCreate(EventRegister $register)
{
Run::attachTemplateRender(ServerManager::getInstance()->getSwooleServer());
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.