Skip to content

Commit

Permalink
Implement ArrayExpected exception
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhicks committed Jan 15, 2012
1 parent e45da50 commit e5aa632
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 14 additions & 0 deletions application/MantisBT/Exception/GPC/ArrayExpected.php
@@ -0,0 +1,14 @@
<?php
namespace MantisBT\Exception\GPC;
use MantisBT\Exception\ExceptionAbstract;

require_api('lang_api.php');

class ArrayExpected extends ExceptionAbstract {
public function __construct($variableName) {
$errorMessage = lang_get(ERROR_GPC_ARRAY_EXPECTED, null, false);
$errorMessage = sprintf($errorMessage, $variableName);
parent::__construct(ERROR_GPC_ARRAY_EXPECTED, $errorMessage, null);
$this->responseCode = 400;
}
}
10 changes: 4 additions & 6 deletions application/core/gpc_api.php
Expand Up @@ -32,6 +32,7 @@
*/

use MantisBT\Exception\Field\EmptyField;
use MantisBT\Exception\GPC\ArrayExpected;
use MantisBT\Exception\GPC\ArrayUnexpected;

require_api( 'config_api.php' );
Expand Down Expand Up @@ -259,8 +260,7 @@ function gpc_get_string_array( $p_var_name, $p_default = null ) {

# If we the result isn't the default we were given or an array, error
if( !((( 1 < func_num_args() ) && ( $t_result === $p_default ) ) || is_array( $t_result ) ) ) {
error_parameters( $p_var_name );
trigger_error( ERROR_GPC_ARRAY_EXPECTED, ERROR );
throw new ArrayExpected( $p_var_name );
}

return $t_result;
Expand All @@ -282,8 +282,7 @@ function gpc_get_int_array( $p_var_name, $p_default = null ) {

# If we the result isn't the default we were given or an array, error
if( !((( 1 < func_num_args() ) && ( $t_result === $p_default ) ) || is_array( $t_result ) ) ) {
error_parameters( $p_var_name );
trigger_error( ERROR_GPC_ARRAY_EXPECTED, ERROR );
throw new ArrayExpected( $p_var_name );
}

$t_count = count( $t_result );
Expand All @@ -309,8 +308,7 @@ function gpc_get_bool_array( $p_var_name, $p_default = null ) {

# If we the result isn't the default we were given or an array, error
if( !((( 1 < func_num_args() ) && ( $t_result === $p_default ) ) || is_array( $t_result ) ) ) {
error_parameters( $p_var_name );
trigger_error( ERROR_GPC_ARRAY_EXPECTED, ERROR );
throw new ArrayExpected( $p_var_name );
}

$t_count = count( $t_result );
Expand Down

0 comments on commit e5aa632

Please sign in to comment.