Blame view

app/library/App/Resources/ProjectResource.php 3.24 KB
4690c1db   Alex Savenko   create project
1
2
3
4
5
6
7
8
9
10
  <?php
  /**
   * Created by PhpStorm.
   * User: Alex Savenko
   * Date: 09.02.2017
   * Time: 14:38
   */
  
  namespace App\Resources;
  
0b8d4ffc   Alex Savenko   Add Roles.
11
12
  use App\Controllers\ProjectController;
  use PhalconApi\Constants\HttpMethods;
4690c1db   Alex Savenko   create project
13
14
15
16
17
  use PhalconRest\Api\ApiEndpoint;
  use PhalconRest\Api\ApiResource;
  use App\Model\Project;
  use PhalconRest\Transformers\ModelTransformer;
  use App\Constants\AclRoles;
4690c1db   Alex Savenko   create project
18
19
20
21
22
23
24
25
26
27
28
29
  
  class ProjectResource extends ApiResource {
  
      public function initialize()
      {
          $this
              ->name('Project')
              ->model(Project::class)
              ->expectsJsonData()
              ->transformer(ModelTransformer::class)
              ->itemKey('project')
              ->collectionKey('projects')
0b8d4ffc   Alex Savenko   Add Roles.
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
              ->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
                      )
                  );
              /** ----------------------------------------------------------------- **/
4690c1db   Alex Savenko   create project
84
85
86
      }
  
  }