1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Blitz PHP framework. |
5
|
|
|
* |
6
|
|
|
* (c) 2022 Dimitri Sitchet Tomkeu <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view |
9
|
|
|
* the LICENSE file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace BlitzPHP\Controllers; |
13
|
|
|
|
14
|
|
|
use Psr\Http\Message\ResponseInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Un contrôleur extensible pour fournir une API RESTful pour une ressource. |
18
|
|
|
*/ |
19
|
|
|
class ResourceController extends RestController |
20
|
|
|
{ |
21
|
|
|
protected string $returnFormat = ''; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritDoc} |
25
|
|
|
*/ |
26
|
|
|
public function __construct() |
27
|
|
|
{ |
28
|
|
|
parent::__construct(); |
29
|
|
|
$this->setFormat($this->returnFormat); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Renvoie un tableau d'objets ressources, eux-mêmes au format tableau |
34
|
|
|
* |
35
|
|
|
* @return ResponseInterface|string|void |
36
|
|
|
*/ |
37
|
|
|
public function index() |
38
|
|
|
{ |
39
|
|
|
return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__])); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Renvoyer les propriétés d'un objet ressource |
44
|
|
|
* |
45
|
|
|
* @param int|string|null $id |
46
|
|
|
* |
47
|
|
|
* @return ResponseInterface|string|void |
48
|
|
|
*/ |
49
|
|
|
public function show($id = null) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__])); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Renvoie un nouvel objet ressource, avec les propriétés par défaut |
56
|
|
|
* |
57
|
|
|
* @return ResponseInterface|string|void |
58
|
|
|
*/ |
59
|
|
|
public function new() |
60
|
|
|
{ |
61
|
|
|
return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__])); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Créer un nouvel objet ressource, à partir des données envoyées |
66
|
|
|
* |
67
|
|
|
* @return ResponseInterface|string|void |
68
|
|
|
*/ |
69
|
|
|
public function create() |
70
|
|
|
{ |
71
|
|
|
return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__])); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Renvoyer les propriétés modifiables d'un objet ressource |
76
|
|
|
* |
77
|
|
|
* @param int|string|null $id |
78
|
|
|
* |
79
|
|
|
* @return ResponseInterface|string|void |
80
|
|
|
*/ |
81
|
|
|
public function edit($id = null) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__])); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Ajouter ou mettre à jour une ressource de modèle, à partir de données envoyées |
88
|
|
|
* |
89
|
|
|
* @param int|string|null $id |
90
|
|
|
* |
91
|
|
|
* @return ResponseInterface|string|void |
92
|
|
|
*/ |
93
|
|
|
public function update($id = null) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__])); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Supprimer l'objet ressource désigné du modèle |
100
|
|
|
* |
101
|
|
|
* @param int|string|null $id |
102
|
|
|
* |
103
|
|
|
* @return ResponseInterface|string|void |
104
|
|
|
*/ |
105
|
|
|
public function delete($id = null) |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__])); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Définir/modifier la représentation de réponse attendue pour les objets renvoyés |
112
|
|
|
* |
113
|
|
|
* @param string $format json/xml |
114
|
|
|
* |
115
|
|
|
* @return void |
116
|
|
|
*/ |
117
|
|
|
public function setFormat(string $format = 'json') |
118
|
|
|
{ |
119
|
|
|
if (in_array($format, ['json', 'xml'], true)) { |
120
|
|
|
$this->returnFormat($format); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.