ProjectResource.php
3.24 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
79
80
81
82
83
84
85
86
<?php
/**
* Created by PhpStorm.
* User: Alex Savenko
* Date: 09.02.2017
* Time: 14:38
*/
namespace App\Resources;
use App\Controllers\ProjectController;
use PhalconApi\Constants\HttpMethods;
use PhalconRest\Api\ApiEndpoint;
use PhalconRest\Api\ApiResource;
use App\Model\Project;
use PhalconRest\Transformers\ModelTransformer;
use App\Constants\AclRoles;
class ProjectResource extends ApiResource {
public function initialize()
{
$this
->name('Project')
->model(Project::class)
->expectsJsonData()
->transformer(ModelTransformer::class)
->itemKey('project')
->collectionKey('projects')
->deny(AclRoles::ALL_ROLES)
->handler(ProjectController::class)
/** -------------------- [GET] projects ----------------------------- **/
->endpoint(ApiEndpoint::factory('/', HttpMethods::GET, 'allAction')
->name(ApiEndpoint::ALL)
->description('Returns all items')
->allow(
AclRoles::ADMINISTRATOR,
AclRoles::USER,
AclRoles::EDITOR,
AclRoles::AUTHOR
)
)
/** ----------------------------------------------------------------- **/
/** -------------------- [POST] projects ---------------------------- **/
->endpoint(ApiEndpoint::factory('/', HttpMethods::POST, 'create')
->name(ApiEndpoint::CREATE)
->description('Creates a new item using the posted data')
->allow(
AclRoles::ADMINISTRATOR,
AclRoles::USER
)
)
/** ----------------------------------------------------------------- **/
/** -------------------- [GET] projects/{id} ------------------------ **/
->endpoint(ApiEndpoint::find()
->allow(AclRoles::ADMINISTRATOR)
)
/** ----------------------------------------------------------------- **/
/** -------------------- [PUT] projects/{id} ------------------------ **/
->endpoint(ApiEndpoint::factory('/{id}', HttpMethods::PUT, 'update')
->name(ApiEndpoint::UPDATE)
->description('Updates an existing item identified by {id}, using the posted data')
->allow(
AclRoles::ADMINISTRATOR,
AclRoles::USER
)
)
/** ----------------------------------------------------------------- **/
/** -------------------- [DELETE] projects/{id} --------------------- **/
->endpoint(ApiEndpoint::factory('/{id}', HttpMethods::DELETE, 'remove')
->name(ApiEndpoint::REMOVE)
->description('Removes the item identified by {id}')
->allow(
AclRoles::ADMINISTRATOR,
AclRoles::USER
)
);
/** ----------------------------------------------------------------- **/
}
}