xref: /php-src/ext/intl/collator/collator_error.c (revision 11accb5c)
1 /*
2    +----------------------------------------------------------------------+
3    | This source file is subject to version 3.01 of the PHP license,      |
4    | that is bundled with this package in the file LICENSE, and is        |
5    | available through the world-wide-web at the following url:           |
6    | https://www.php.net/license/3_01.txt                                 |
7    | If you did not receive a copy of the PHP license and are unable to   |
8    | obtain it through the world-wide-web, please send a note to          |
9    | license@php.net so we can mail you a copy immediately.               |
10    +----------------------------------------------------------------------+
11    | Authors: Vadim Savchuk <vsavchuk@productengine.com>                  |
12    |          Dmitry Lakhtyuk <dlakhtyuk@productengine.com>               |
13    +----------------------------------------------------------------------+
14  */
15 
16 #ifdef HAVE_CONFIG_H
17 #include <config.h>
18 #endif
19 
20 #include "php_intl.h"
21 #include "collator_class.h"
22 
23 /* {{{ Get collator's last error code. */
PHP_FUNCTION(collator_get_error_code)24 PHP_FUNCTION( collator_get_error_code )
25 {
26 	COLLATOR_METHOD_INIT_VARS
27 
28 	/* Parse parameters. */
29 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
30 		&object, Collator_ce_ptr ) == FAILURE )
31 	{
32 		RETURN_THROWS();
33 	}
34 
35 	/* Fetch the object (without resetting its last error code). */
36 	co = Z_INTL_COLLATOR_P(object);
37 	if( co == NULL )
38 		RETURN_FALSE;
39 
40 	/* Return collator's last error code. */
41 	RETURN_LONG( COLLATOR_ERROR_CODE( co ) );
42 }
43 /* }}} */
44 
45 /* {{{ Get text description for collator's last error code. */
PHP_FUNCTION(collator_get_error_message)46 PHP_FUNCTION( collator_get_error_message )
47 {
48 	zend_string* message = NULL;
49 
50 	COLLATOR_METHOD_INIT_VARS
51 
52 	/* Parse parameters. */
53 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
54 		&object, Collator_ce_ptr ) == FAILURE )
55 	{
56 		RETURN_THROWS();
57 	}
58 
59 	/* Fetch the object (without resetting its last error code). */
60 	co = Z_INTL_COLLATOR_P( object );
61 	if( co == NULL )
62 		RETURN_FALSE;
63 
64 	/* Return last error message. */
65 	message = intl_error_get_message( COLLATOR_ERROR_P( co ) );
66 	RETURN_STR(message);
67 }
68 /* }}} */
69