1. Go to this page and download the library: Download landao/webman-core 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/ */
namespace app\controller;
use Landao\WebmanCore\Annotation\Router\Get;
use Landao\WebmanCore\Annotation\Router\Group;
use Landao\WebmanCore\Annotation\Router\Post;
use support\Request;
use support\Response;
#[Group('/user')]
class UserController
{
#[Get('/index')]
public function index()
{
try {
// 假设这里有一些业务逻辑
$response = [
'status' => 'success',
'message' => 'Welcome to the user page!'
];
return json($response);
} catch (\Exception $e) {
// 记录异常日志
Log::error($e->getMessage());
// 返回错误响应
return json(['status' => 'error', 'message' => 'An error occurred'], 500);
}
}
#[Post('/test/123')]
public function test(): Response
{
return json('ceshi');
}
}
namespace app\controller;
use Landao\WebmanCore\Annotation\Router\Get;
use Landao\WebmanCore\Annotation\Router\Group;
use Landao\WebmanCore\Annotation\Router\Post;
use Landao\WebmanCore\Annotation\Validation;
use Landao\WebmanCore\Annotation\Validation\Required;
use Landao\WebmanCore\Annotation\Validation\Regex;
use Landao\WebmanCore\Http\FormRequest;
use support\Log;
use support\Request;
use support\Response;
#[Group('/user')]
class UserController
{
#[Post('/test/123')]
// #[Regex("message", ruleValue: "~^\w+$~", attribute: "留言")]
#[Validation(field: "message", rule: "tion test2(FormRequest $request):Response
{
return json('ceshi2');
}
}
namespace app\controller;
use Landao\WebmanCore\Annotation\Router\Get;
use Landao\WebmanCore\Annotation\Router\Group;
use Landao\WebmanCore\Annotation\Router\Post;
use Landao\WebmanCore\Annotation\Validation;
use Landao\WebmanCore\Annotation\Validation\Required;
use Landao\WebmanCore\Annotation\Validation\Regex;
use Landao\WebmanCore\Http\FormRequest;
use support\Log;
use support\Request;
use support\Response;
#[Group('/user')]
class UserController
{
#[Post('/test/12')]
#[Validation(class: UserRequest::class)]
public function test2(FormRequest $request):Response
{
return json('ceshi2');
}
}
throw new UnauthorizedHttpException('账号或密码错误',['errorCode'=>40001]);
namespace plugin\system\app\enum;
use Landao\WebmanCore\Exceptions\ErrorCodeInterface;
use Landao\WebmanCore\Annotation\Description;
use Landao\WebmanCore\Enum\EnumExtend;
/**
* 错误码枚举
* 错误码规则:模块编号-功能编号-错误码编号-错误码序号 1_002_001_000
*/
enum ErrorCodeConstants: int implements ErrorCodeInterface
{
use EnumExtend;
// ========== 菜单模块 1-002-001-000 ==========
#[Description('已经存在该名字的菜单')]
case MENU_NAME_DUPLICATE = 1_002_001_000;
#[Description('父菜单({})不存在<{}>')]
case MENU_PARENT_NOT_EXISTS = 1_002_001_001;
#[Description('不能设置{0}自己为父菜单{1}')]
case MENU_PARENT_ERROR = 1_002_001_002;
public function getValue(): int
{
return $this->value;
}
}