diff --git a/api/rest/restcore/lang_rest.php b/api/rest/restcore/lang_rest.php index cbb621a939..33814efa6b 100644 --- a/api/rest/restcore/lang_rest.php +++ b/api/rest/restcore/lang_rest.php @@ -46,23 +46,14 @@ * @return \Slim\Http\Response The augmented response. */ function rest_lang_get( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) { - $t_strings = $p_request->getParam( 'string' ); - if( !is_array( $t_strings ) ) { - $t_strings = array( $t_strings ); - } - - $t_current_language = lang_get_current(); - $t_localized_strings = array(); - foreach( $t_strings as $t_string ) { - if( !lang_exists( $t_string, $t_current_language) ) { - continue; - } - - $t_localized_strings[] = array( 'name' => $t_string, 'localized' => lang_get( $t_string ) ); - } - - $t_result = array( 'strings' => $t_localized_strings ); - $t_result['language'] = $t_current_language; + $t_data = array( + 'query' => array( + 'string' => $p_request->getParam( 'string' ) + ) + ); + + $t_command = new LocalizedStringsGetCommand( $t_data ); + $t_result = $t_command->execute(); return $p_response->withStatus( HTTP_STATUS_SUCCESS )->withJson( $t_result ); } diff --git a/core/commands/LocalizedStringsGetCommand.php b/core/commands/LocalizedStringsGetCommand.php new file mode 100644 index 0000000000..d698ff000a --- /dev/null +++ b/core/commands/LocalizedStringsGetCommand.php @@ -0,0 +1,64 @@ +. + +/** + * A command that gets a set of localized strings. + */ +class LocalizedStringsGetCommand extends Command { + /** + * Constructor + * + * @param array $p_data The command data. + */ + function __construct( array $p_data ) { + parent::__construct( $p_data ); + } + + /** + * Validate the data. + */ + function validate() { + } + + /** + * Process the command. + * + * @returns array Command response + */ + protected function process() { + $t_strings = $this->query( 'string' ); + if( !is_array( $t_strings ) ) { + $t_strings = array( $t_strings ); + } + + $t_current_language = lang_get_current(); + $t_localized_strings = array(); + + foreach( $t_strings as $t_string ) { + if( !lang_exists( $t_string, $t_current_language ) ) { + continue; + } + + $t_localized_strings[] = array( 'name' => $t_string, 'localized' => lang_get( $t_string ) ); + } + + return array( + 'strings' => $t_localized_strings, + 'language' => $t_current_language, + ); + } +} +