-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityController.php
More file actions
78 lines (70 loc) · 2.58 KB
/
EntityController.php
File metadata and controls
78 lines (70 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace App\Controller;
use PhpRest2\Controller\Attribute\{Controller, Action, Summary, Param};
use App\Entity\{User, Info};
use App\Entity\Nested\Company;
use App\Entity\Inherit\ObjSon;
#[Controller('/entity')]
class EntityController
{
/***************************************************************************************
*
**************************************************************************************/
#[Action('POST:/demo1')]
public function demo1(User $user)
{
return $user;
}
/***************************************************************************************
* 绑定到实体类数组
**************************************************************************************/
#[Action('POST:/demo2')]
#[Param(name: 'users', type: User::class)]
public function demo2(array $users)
{
return $users;
}
/***************************************************************************************
*
**************************************************************************************/
#[Action('POST:/demo3')]
public function demo3(User $user, Info $info)
{
return [
'user' => $user,
'info' => $info,
];
}
/***************************************************************************************
* 实体类嵌套实体类, 嵌套实体类数组, 嵌套基础类型数组
**************************************************************************************/
#[Action('POST:/demo4')]
public function demo4(Company $company)
{
return $company;
}
/***************************************************************************************
* 实体类支持继承
**************************************************************************************/
#[Action('POST:/demo5')]
public function demo5(ObjSon $son)
{
return $son;
}
/***************************************************************************************
* 绑定参数为实体类有两种方式
*
* #[Param(name: 'users', type: User::class)]
* 或
* public function demo1(User $user)
* 二选一,优先取 Param 注解
*
* 此方法中user只是个array, 并不是一个实体类
**************************************************************************************/
#[Action('POST:/demo6')]
public function demo6($user)
{
return $user;
}
}