Blame view

app/library/App/Mvc/ExtendedApiCollection.php 1.15 KB
5166024b   Alex Savenko   extended classes
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
  <?php
  /**
   * Created by PhpStorm.
   * User: Alex Savenko
   * Date: 14.02.2017
   * Time: 16:32
   */
  
  namespace App\Mvc;
  
  
  use PhalconApi\Constants\HttpMethods;
  use PhalconRest\Api\ApiCollection;
  
  class ExtendedApiCollection extends ApiCollection {
  
      public function endpoint(ExtendedApiEndpoint $endpoint)
      {
          $this->endpointsByName[$endpoint->getName()] = $endpoint;
  
          switch ($endpoint->getHttpMethod()) {
  
              case HttpMethods::GET:
  
                  $this->get($endpoint->getPath(), $endpoint->getHandlerMethod(), $this->createRouteName($endpoint));
                  break;
  
              case HttpMethods::POST:
  
                  $this->post($endpoint->getPath(), $endpoint->getHandlerMethod(), $this->createRouteName($endpoint));
                  break;
  
              case HttpMethods::PUT:
  
                  $this->put($endpoint->getPath(), $endpoint->getHandlerMethod(), $this->createRouteName($endpoint));
                  break;
  
              case HttpMethods::DELETE:
  
                  $this->delete($endpoint->getPath(), $endpoint->getHandlerMethod(), $this->createRouteName($endpoint));
                  break;
          }
  
          return $this;
      }
  
  }