|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bludata\Lumen\Application; |
|
4
|
|
|
|
|
5
|
|
|
use Closure; |
|
6
|
|
|
use Laravel\Lumen\Application; |
|
7
|
|
|
|
|
8
|
|
|
abstract class BaseApplication extends Application |
|
9
|
|
|
{ |
|
10
|
|
|
protected $currentUser; |
|
11
|
|
|
|
|
12
|
|
|
abstract public function getRepositoryInterface($entity); |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
public function getCurrentUser() |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
return $this->currentUser; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function setCurrentUser($currentUser) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->currentUser = $currentUser; |
|
22
|
|
|
|
|
23
|
|
|
return $this; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return Bludata\Lumen\Application\BaseApplication |
|
|
|
|
|
|
28
|
|
|
*/ |
|
29
|
|
|
public function resource($descriptionGroup, $prefix, $controller, array $except = [], Closure $routes = null) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$exceptAll = false; |
|
32
|
|
|
|
|
33
|
|
|
if (isset($except[0])) { |
|
34
|
|
|
$exceptAll = $except[0] == '*'; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (!$exceptAll) { |
|
38
|
|
View Code Duplication |
if (!in_array('index', $except)) { |
|
|
|
|
|
|
39
|
|
|
$this->get($prefix, [ |
|
40
|
|
|
'as' => $prefix.'.index', |
|
41
|
|
|
'uses' => $controller.'@index', |
|
42
|
|
|
'description' => 'Buscar todos', |
|
43
|
|
|
'descriptionGroup' => $descriptionGroup, |
|
44
|
|
|
]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (!in_array('show', $except)) { |
|
48
|
|
|
$this->get($prefix.'/{id:[0-9]+}', [ |
|
49
|
|
|
'as' => $prefix.'.show', |
|
50
|
|
|
'uses' => $controller.'@show', |
|
51
|
|
|
'description' => 'Buscar um', |
|
52
|
|
|
'descriptionGroup' => $descriptionGroup, |
|
53
|
|
|
]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if (!in_array('store', $except)) { |
|
57
|
|
|
$this->post($prefix, [ |
|
58
|
|
|
'as' => $prefix.'.store', |
|
59
|
|
|
'uses' => $controller.'@store', |
|
60
|
|
|
'description' => 'Cadastrar', |
|
61
|
|
|
'descriptionGroup' => $descriptionGroup, |
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
View Code Duplication |
if (!in_array('update', $except)) { |
|
|
|
|
|
|
66
|
|
|
$this->put($prefix.'/{id:[0-9]+}', [ |
|
67
|
|
|
'as' => $prefix.'.update', |
|
68
|
|
|
'uses' => $controller.'@update', |
|
69
|
|
|
'description' => 'Editar', |
|
70
|
|
|
'descriptionGroup' => $descriptionGroup, |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (!in_array('destroy', $except)) { |
|
75
|
|
|
$this->delete($prefix.'/{id:[0-9]+}', [ |
|
76
|
|
|
'as' => $prefix.'.destroy', |
|
77
|
|
|
'uses' => $controller.'@destroy', |
|
78
|
|
|
'description' => 'Excluir', |
|
79
|
|
|
'descriptionGroup' => $descriptionGroup, |
|
80
|
|
|
]); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
if ($routes instanceof Closure) { |
|
85
|
|
|
$routes($descriptionGroup, $prefix, $controller); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@returndoc comment to communicate to implementors of these methods what they are expected to return.