基本クラスを作成するときは、徐々に開発し、必要なもの (またはテストしているもの) だけを作成することがよくあります。それでも、インターフェースのバランスが取れているのが好きです。すべてのゲッターに対してセッター。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();
}
}