冗長性を考えると、これを行うためのより良い方法はありますか?もしそうなら、それはどのように見えるでしょうか?
$method
クラス内で関数名として渡される最初の引数に注意してください$api
。API関数に引数として渡してはなりません。その後のすべての議論は存在しないかもしれません。
function jsonRequest( $method )
{
$api = new JsonRpcClient( 'https://api.example.com' );
switch ( func_num_args() ) {
case 2:
$result = $api->$method( 'AccountRef', 'APIKey', func_get_arg( 1 ) );
break; case 3:
$result = $api->$method( 'AccountRef', 'APIKey', func_get_arg( 1 ), func_get_arg( 2 ) );
break; case 4:
$result = $api->$method( 'AccountRef', 'APIKey', func_get_arg( 1 ), func_get_arg( 2 ), func_get_arg( 3 ) );
break; case 5:
$result = $api->$method( 'AccountRef', 'APIKey', func_get_arg( 1 ), func_get_arg( 2 ), func_get_arg( 3 ), func_get_arg( 4 ) );
break;
}
return json_decode( $result );
}