xref: /PHP-7.1/ext/intl/collator/collator_error.c (revision bdeb220f)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | http://www.php.net/license/3_01.txt                                  |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors: Vadim Savchuk <vsavchuk@productengine.com>                  |
14    |          Dmitry Lakhtyuk <dlakhtyuk@productengine.com>               |
15    +----------------------------------------------------------------------+
16  */
17 
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include "php_intl.h"
23 #include "collator_class.h"
24 #include "collator_error.h"
25 
26 /* {{{ proto int Collator::getErrorCode( Collator $coll )
27  * Get collator's last error code. }}} */
28 /* {{{ proto int collator_get_error_code( Collator $coll )
29  * Get collator's last error code.
30  */
PHP_FUNCTION(collator_get_error_code)31 PHP_FUNCTION( collator_get_error_code )
32 {
33 	COLLATOR_METHOD_INIT_VARS
34 
35 	/* Parse parameters. */
36 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
37 		&object, Collator_ce_ptr ) == FAILURE )
38 	{
39 		intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
40 			"collator_get_error_code: unable to parse input params", 0 );
41 
42 		RETURN_FALSE;
43 	}
44 
45 	/* Fetch the object (without resetting its last error code). */
46 	co = Z_INTL_COLLATOR_P(object);
47 	if( co == NULL )
48 		RETURN_FALSE;
49 
50 	/* Return collator's last error code. */
51 	RETURN_LONG( COLLATOR_ERROR_CODE( co ) );
52 }
53 /* }}} */
54 
55 /* {{{ proto string Collator::getErrorMessage( Collator $coll )
56  * Get text description for collator's last error code. }}} */
57 /* {{{ proto string collator_get_error_message( Collator $coll )
58  * Get text description for collator's last error code.
59  */
PHP_FUNCTION(collator_get_error_message)60 PHP_FUNCTION( collator_get_error_message )
61 {
62 	zend_string* message = NULL;
63 
64 	COLLATOR_METHOD_INIT_VARS
65 
66 	/* Parse parameters. */
67 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
68 		&object, Collator_ce_ptr ) == FAILURE )
69 	{
70 		intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
71 			"collator_get_error_message: unable to parse input params", 0 );
72 
73 		RETURN_FALSE;
74 	}
75 
76 	/* Fetch the object (without resetting its last error code). */
77 	co = Z_INTL_COLLATOR_P( object );
78 	if( co == NULL )
79 		RETURN_FALSE;
80 
81 	/* Return last error message. */
82 	message = intl_error_get_message( COLLATOR_ERROR_P( co ) );
83 	RETURN_STR(message);
84 }
85 /* }}} */
86 
87 /*
88  * Local variables:
89  * tab-width: 4
90  * c-basic-offset: 4
91  * End:
92  * vim600: noet sw=4 ts=4 fdm=marker
93  * vim<600: noet sw=4 ts=4
94  */
95