Skip to content

Commit

Permalink
- Extract invalid param
Browse files Browse the repository at this point in the history
  • Loading branch information
daycry committed Mar 30, 2022
1 parent c608c12 commit 003cd5f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Exceptions/ForbiddenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public static function forOnlyAjax()
return new self( lang( 'Rest.textRestAjaxOnly' ) );
}

public static function validationtMethodParamsError()
public static function validationtMethodParamsError( $param )
{
return new self( lang( 'Rest.textInvalidMethodParams' ) );
$parser = \Config\Services::parser();
return new self( $parser->setData( array( 'param' => $param ) )->renderString( lang( 'Rest.textInvalidMethodParams' ) ) );
}
}
2 changes: 1 addition & 1 deletion src/Language/en/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'textRestApiKeyUnauthorized' => 'This API key does not have access to the requested controller',
'textInvalidUserClassConfiguration' => 'Invalid user class configuration, extends( \Daycry\RestServer\Libraries\User\UserAbstract )',
'textRestAjaxOnly' => 'Only AJAX requests are allowed',
'textInvalidMethodParams' => 'Invalid params for this method'
'textInvalidMethodParams' => 'Invalid params for this method: {param}'
];

/*
Expand Down
2 changes: 1 addition & 1 deletion src/RestServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ protected function validation( String $rules, \Config\Validation $config = null,
{
if( !array_key_exists( $key, $config->{$rules} ) )
{
throw ForbiddenException::validationtMethodParamsError();
throw ForbiddenException::validationtMethodParamsError( $key );
}
}
}
Expand Down

0 comments on commit 003cd5f

Please sign in to comment.