状況は次のとおりです。
ページコンテンツの生成を担当する別のオブジェクトがあり、それをContentと呼ぶことができます。もう 1 つのオブジェクトは、その親であるコアオブジェクトです。 コンテンツオブジェクトはコアメソッド *Check_parameters_count($parameters_count)* を呼び出すため、コアは URI 内の指定されたパラメーター カウントがこのメソッドの実行中に指定された整数 ($parameters_count) と等しいかどうかを確認する必要があります。そうでない場合、コアはエラー ページを生成し、実行を停止する必要があります。コンテンツのレンダリング方法。
if文を使わずにこれを行う方法はありますか? 特定のレンダリング エンジン プログラマの作業を簡素化するために、コンテンツクラスで*$core->Check_parameters_count(2)* を使用するだけです。
すべてが次のようになります。
class Core {
public function Check_parameters_count($parameters_count) {
if (count($this->parameters) != $parameters_count) {
$this->Show_error(404);
$this->Stop_executing($content, 'Render');
//or
stop($content->Render);
//or something similar..
}
}
}
class Content {
public function Render() {
//check given parameters so we could know which page should be rendered and how many parameters should be given
//...
//lets say we should have exactly 2 parameters
$parameters_count = 2;
//check it
$core->Check_parameters_count($parameters_count);
//if parameters count matched - continue method execution
//...
}
}