xref: /PHP-8.3/ext/intl/collator/collator_locale.c (revision 01b3fc03)
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 #include "intl_convert.h"
23 
24 #include <zend_API.h>
25 
26 /* {{{ Gets the locale name of the collator. */
PHP_FUNCTION(collator_get_locale)27 PHP_FUNCTION( collator_get_locale )
28 {
29 	zend_long   type        = 0;
30 	char*  locale_name = NULL;
31 
32 	COLLATOR_METHOD_INIT_VARS
33 
34 	/* Parse parameters. */
35 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol",
36 		&object, Collator_ce_ptr, &type ) == FAILURE )
37 	{
38 		RETURN_THROWS();
39 	}
40 
41 	/* Fetch the object. */
42 	COLLATOR_METHOD_FETCH_OBJECT;
43 
44 	if (!co || !co->ucoll) {
45 		intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
46 		intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
47 			"Object not initialized", 0 );
48 		zend_throw_error(NULL, "Object not initialized");
49 
50 		RETURN_THROWS();
51 	}
52 
53 	/* Get locale by specified type. */
54 	locale_name = (char*) ucol_getLocaleByType(
55 		co->ucoll, type, COLLATOR_ERROR_CODE_P( co ) );
56 	COLLATOR_CHECK_STATUS( co, "Error getting locale by type" );
57 
58 	/* Return it. */
59 	RETVAL_STRINGL( locale_name, strlen(locale_name) );
60 }
61 /* }}} */
62