179 abstract protected function create();
180 abstract protected function sanitize($x);
181 abstract protected function select($x);
182 abstract protected function get($x);
183 abstract protected function insert($x);
184 abstract protected function update($x);
185 abstract protected function delete($x);
186 abstract protected function validateUpdate($x);
187 protected function validateInsert($x)
189 return $this->validateUpdate($x);
191 protected function validateKey($x)
194 if (! is_object($x)) {
195 throw new \InvalidArgumentException();
199 return _(
"Empty ID");
201 public function doSelect()
204 $req = (object) $this->sanitize((
object) $_REQUEST);
205 $list = $this->select($req);
206 $model_name = (new \ReflectionClass($this))->getShortName();
207 return $this->render(
208 "{$model_name}Index",
214 public function doGet()
217 $req = (object) $this->sanitize((
object) $_REQUEST);
218 $err = $this->validateKey($req);
220 return $this->doSelect();
221 $data = $this->
get($req);
223 return $this->renderError(_(
"Not found"), 404);
224 $model_name = (new \ReflectionClass($this))->getShortName();
225 return $this->render(
226 "{$model_name}Editor",
230 "permissions" => (
object) [
231 "can_insert" =>
false,
232 "can_update" =>
true,
237 public function doAdd()
240 $req = (object) $this->sanitize((
object) $_REQUEST);
241 $data = (object) $this->create();
242 $model_name = (new \ReflectionClass($this))->getShortName();
243 return $this->render(
244 "{$model_name}Editor",
248 "permissions" => (
object) [
249 "can_insert" =>
true,
250 "can_update" =>
false,
251 "can_delete" =>
false
255 public function doInsert()
258 $req = (object) $this->sanitize((
object) $_REQUEST);
259 $err = $this->validateInsert($req);
261 return $this->renderError($err, 400);
263 return $this->doSelect();
265 public function doUpdate()
268 $req = (object) $this->sanitize((
object) $_REQUEST);
269 $err = $this->validateKey($req);
271 return $this->renderError($err, 400);
272 $err = $this->validateUpdate($req);
274 return $this->renderError($err, 400);
276 return $this->doSelect();
278 public function doDelete()
281 $req = (object) $this->sanitize((
object) $_REQUEST);
282 $err = $this->validateKey($req);
284 return $this->renderError($err, 400);
286 return $this->doSelect();