1
|
|
|
<?php |
2
|
|
|
namespace Solvire\API\Representatives; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Providing some basic CRUD level stuff |
6
|
|
|
* |
7
|
|
|
* @author solvire <[email protected]> |
8
|
|
|
* @package RepresentationControllers |
9
|
|
|
* @namespace namespace Solvire\API\Representatives; |
10
|
|
|
*/ |
11
|
|
|
class GenericRepresentationController extends BaseRepresentationController |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
protected $availableMethods = [ |
15
|
|
|
'GET', |
16
|
|
|
'POST', |
17
|
|
|
'PUT', |
18
|
|
|
'DELETE', |
19
|
|
|
'OPTIONS' |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
protected $recordCount = 0; |
23
|
|
|
|
24
|
|
|
protected $hasMorePages = false; |
25
|
|
|
|
26
|
|
|
protected $isEmpty = true; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
*/ |
30
|
|
|
// public function recordCount() |
|
|
|
|
31
|
|
|
// { |
32
|
|
|
// return $this->recordCount(); |
33
|
|
|
// } |
34
|
|
|
|
35
|
|
|
// public function hasMorePages() |
|
|
|
|
36
|
|
|
// { |
37
|
|
|
// return (boolean) $this->hasMorePages; |
38
|
|
|
// } |
39
|
|
|
|
40
|
1 |
|
public function process() |
41
|
|
|
{ |
42
|
1 |
|
$method = $this->request->getMethod(); |
43
|
1 |
|
$this->renderer->setRequest($this->request); |
44
|
1 |
|
$this->renderer->setSerializer($this->serializer); |
45
|
|
|
|
46
|
|
|
// check to make sure the method exists for the renderer has the method |
47
|
|
|
// for instance if it's List obj then we will have the appropriate render functions. |
48
|
|
|
// if we have a List and we call a put render |
49
|
|
|
switch ($method) { |
50
|
|
|
|
51
|
1 |
|
case 'GET': |
52
|
1 |
|
return $this->get(); |
53
|
|
|
break; |
|
|
|
|
54
|
1 |
|
case 'POST': |
55
|
1 |
|
return $this->post(); |
56
|
|
|
break; |
|
|
|
|
57
|
1 |
|
case 'PUT': |
58
|
1 |
|
return $this->put(); |
59
|
|
|
break; |
|
|
|
|
60
|
1 |
|
case 'DELETE': |
61
|
1 |
|
return $this->delete(); |
62
|
|
|
break; |
|
|
|
|
63
|
1 |
|
case 'OPTIONS': |
64
|
1 |
|
return $this->options(); |
65
|
|
|
break; |
|
|
|
|
66
|
1 |
|
default: |
67
|
1 |
|
throw new \RuntimeException("No Valid Method Provided"); |
68
|
1 |
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
1 |
|
public function get() |
73
|
|
|
{ |
74
|
1 |
|
throw new \RuntimeException('Not implemented'); |
75
|
|
|
} |
76
|
|
|
|
77
|
1 |
|
public function post() |
78
|
|
|
{ |
79
|
1 |
|
throw new \RuntimeException('Not implemented'); |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
public function put() |
83
|
|
|
{ |
84
|
1 |
|
throw new \RuntimeException('Not implemented'); |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
public function delete() |
88
|
|
|
{ |
89
|
1 |
|
throw new \RuntimeException('Not implemented'); |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
public function options() |
93
|
|
|
{ |
94
|
1 |
|
throw new \RuntimeException('Not implemented'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.