1. Go to this page and download the library: Download xeewill/webman-exception 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/ */
use support\Request;
use support\Response;
use Tinywan\ExceptionHandler\Exception\BadRequestHttpException;
class Token{
public function issueToken(Request $request): Response
{
$params = $request->post();
if (empty($params)) {
throw new BadRequestHttpException('账号或密码不能为空');
}
}
}
declare(strict_types=1);
namespace support\exception;
use Tinywan\ExceptionHandler\Exception\BaseException;
class MethodNotAllowedException extends BaseException
{
/**
* @var int
*/
public int $statusCode = 405;
/**
* @var string
*/
public string $errorMessage = '请求行中指定的请求方法不能被用于请求相应的资源';
}
use support\Request;
use support\Response;
use support\exception\MethodNotAllowedException;
class Token{
public function issueToken(Request $request): Response
{
$params = $request->post();
if (empty($params)) {
throw new MethodNotAllowedException();
}
}
}