在编写基类时,我经常逐渐开发,并且只构建我需要的(或者,我正在测试的)。然而,我喜欢我的界面是平衡的。对于每个 getter 一个 setter。在实现 CRUD 时,即使现在,我只需要 R,我宁愿为 CUD 编写存根。
我希望这些抛出一些未实现的异常。如何引发此类错误或异常?
例如:
class Resource {
/**
* get Issues a GET-request to Online, fetch with $this::$id
* @returns $this
*/
protected function get() {
if ($this->id) {
$attributes = http_build_query(array("id" => $this->id));
$url = "{$this->url}?{$attributes}";
$options = array_merge(array('method' => 'GET'));
$response = _http_request($url, $options);
$this->parse($response);
}
return $this;
}
/**
* post Place a new object on Online
*
* @param $attributes ....
* @returns Source $this
*/
protected function post($attributes = array()) {
throw new NotImplementedError();
}
/**
* put Updates an object on Online
*
* @param $attributes ....
* @returns $this
*/
protected function put($attributes = array()) {
throw new NotImplementedError();
}
/**
* delete Removes an object from Online, selected by $this::$id.
* @returns $this
*/
protected function delete() {
throw new NotImplementedError();
}
}