Skip to content

Commit 5cae91f

Browse files
committed
split MINIT for Options
1 parent d7f5a3f commit 5cae91f

File tree

8 files changed

+284
-255
lines changed

8 files changed

+284
-255
lines changed

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Fix: remove package.xml from manifest to avoid md5 checksum errors when installi
8585
<file name="locale_character_direction.h" role="src"/>
8686
<file name="locale_options.c" role="src"/>
8787
<file name="locale_options.h" role="src"/>
88+
<file name="locale_options_arginfo.h" role="src"/>
89+
<file name="locale_options.stub.php" role="src"/>
8890
<file name="locale_text_info.c" role="src"/>
8991
<file name="locale_text_info.h" role="src"/>
9092
<file name="locale_text_info_arginfo.h" role="src"/>

src/php/classes/locale_options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void setRegion(zend_object *object, zend_string *paramStr,
5959
static void setScript(zend_object *object, zend_string *paramStr,
6060
zend_object *paramObj);
6161

62-
void registerEcmaIntlLocaleOptions() {
62+
PHP_MINIT_FUNCTION(ecma_intl_locale_options) {
6363
ecma_ce_IntlLocaleOptions = register_class_Ecma_Intl_Locale_Options(
6464
zend_ce_iterator, php_json_serializable_ce);
6565
ecma_ce_IntlLocaleOptions->create_object = ecma_createIntlLocaleOptions;

src/php/classes/locale_options.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "php/php_common.h"
1717

18+
#include "php/classes/locale_options_arginfo.h"
19+
1820
#define ECMA_LOCALE_OPTION_COUNT 9
1921

2022
typedef enum ecma_localeOption {
@@ -46,7 +48,8 @@ ecma_IntlLocaleOptionsFromObj(zend_object *obj) {
4648
extern zend_class_entry *ecma_ce_IntlLocaleOptions;
4749
extern zend_object_handlers ecma_handlers_IntlLocaleOptions;
4850

49-
void registerEcmaIntlLocaleOptions(void);
5051
zend_object *ecma_createIntlLocaleOptions(zend_class_entry *classEntry);
5152

53+
PHP_MINIT_FUNCTION(ecma_intl_locale_options);
54+
5255
#endif /* ECMA_INTL_PHP_CLASSES_LOCALE_OPTIONS_H */
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?php
2+
3+
/**
4+
* Copyright (c) php-ecma-intl contributors.
5+
*
6+
* This source file is subject to the BSD-3-Clause license that is bundled with
7+
* this package in the file LICENSE and is available at the following web
8+
* address: https://opensource.org/license/bsd-3-clause/
9+
*
10+
* This source file may utilize copyrighted material from third-party open
11+
* source projects, the use of which is acknowledged in the NOTICE file bundled
12+
* with this package.
13+
*
14+
* @generate-class-entries
15+
*/
16+
17+
namespace Ecma\Intl\Locale
18+
{
19+
/**
20+
* Configuration for the locale.
21+
*
22+
* Any property set on the Options object passed to the Locale's
23+
* constructor will override the same properties on the language tag passed
24+
* to the Locale.
25+
*
26+
* @link https://tc39.es/ecma402/#sec-intl-locale-constructor ECMA-402: The Intl.Locale Constructor
27+
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale MDN: Intl.Locale() constructor
28+
*
29+
* @strict-properties
30+
*/
31+
readonly class Options implements \Iterator, \JsonSerializable
32+
{
33+
/**
34+
* The calendar to set on the locale.
35+
*/
36+
public readonly ?string $calendar;
37+
38+
/**
39+
* The case sorting algorithm to set on the locale.
40+
*/
41+
public readonly ?string $caseFirst;
42+
43+
/**
44+
* The collation algorithm to set on the locale.
45+
*/
46+
public readonly ?string $collation;
47+
48+
/**
49+
* The hour cycle to set on the locale.
50+
*/
51+
public readonly ?string $hourCycle;
52+
53+
/**
54+
* The language to set on the locale.
55+
*/
56+
public readonly ?string $language;
57+
58+
/**
59+
* The locale's numbering system
60+
*/
61+
public readonly ?string $numberingSystem;
62+
63+
/**
64+
* Whether to sort a sequence of decimal digits with its numeric value
65+
* (i.e, "A-21" < "A-123")
66+
*/
67+
public readonly ?bool $numeric;
68+
69+
/**
70+
* The locale's region.
71+
*/
72+
public readonly ?string $region;
73+
74+
/**
75+
* The locale's script.
76+
*/
77+
public readonly ?string $script;
78+
79+
/**
80+
* Configuration for the locale
81+
*
82+
* Any property set on the Options object passed to the Locale's
83+
* constructor will override the same properties on the language tag passed
84+
* to the Locale.
85+
*
86+
* @link https://tc39.es/ecma402/#sec-intl-locale-constructor ECMA-402: The Intl.Locale Constructor
87+
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale MDN: Intl.Locale() constructor
88+
*
89+
* @param \Stringable|string|null $calendar The calendar to use with the locale
90+
* @param \Stringable|string|false|null $caseFirst The case sorting algorithm to use with the locale
91+
* @param \Stringable|string|null $collation The collation algorithm to use with the locale
92+
* @param \Stringable|string|null $hourCycle The hour cycle to use with the locale
93+
* @param \Stringable|string|null $language The locale's language
94+
* @param \Stringable|string|null $numberingSystem The locale's numbering system
95+
* @param bool|null $numeric Whether to sort a sequence of decimal digits with its numeric value (i.e, "A-21" < "A-123")
96+
* @param \Stringable|string|null $region The locale's region
97+
* @param \Stringable|string|null $script The locale's script
98+
*/
99+
public function __construct(
100+
\Stringable|string|null $calendar = null,
101+
\Stringable|string|false|null $caseFirst = null,
102+
\Stringable|string|null $collation = null,
103+
\Stringable|string|null $hourCycle = null,
104+
\Stringable|string|null $language = null,
105+
\Stringable|string|null $numberingSystem = null,
106+
?bool $numeric = null,
107+
\Stringable|string|null $region = null,
108+
\Stringable|string|null $script = null,
109+
) {
110+
}
111+
112+
/**
113+
* Returns an object of these options, suitable for serializing to JSON.
114+
*
115+
* @return object
116+
*/
117+
public function jsonSerialize(): object
118+
{
119+
}
120+
121+
/**
122+
* Returns the current element when iterating over the object properties.
123+
*
124+
* This allows the object to be used in array unpacking scenarios. For
125+
* example:
126+
*
127+
* ```php
128+
* use Ecma\Intl\Locale\Options;
129+
* $commonOptions = new Options(hourCycle: 'h23');
130+
* $englishOptions = new Options(...[...$commonOptions, 'language' => 'en']);
131+
* ```
132+
*
133+
* Please note that `null` values will be skipped when iterating over
134+
* them. This facilitates scenarios where you might return JSON-encoded
135+
* values to be used by `Intl.Locale` instances in JavaScript.
136+
*/
137+
public function current(): string|bool
138+
{
139+
}
140+
141+
public function next(): void
142+
{
143+
}
144+
145+
public function key(): string
146+
{
147+
}
148+
149+
public function valid(): bool
150+
{
151+
}
152+
153+
public function rewind(): void
154+
{
155+
}
156+
}
157+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/* This is a generated file, edit the .stub.php file instead.
2+
* Stub hash: a240aabaa65649a7d5a95dc92b9ad0c2752da348 */
3+
4+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Ecma_Intl_Locale_Options___construct, 0, 0, 0)
5+
ZEND_ARG_OBJ_TYPE_MASK(0, calendar, Stringable, MAY_BE_STRING|MAY_BE_NULL, "null")
6+
ZEND_ARG_OBJ_TYPE_MASK(0, caseFirst, Stringable, MAY_BE_STRING|MAY_BE_FALSE|MAY_BE_NULL, "null")
7+
ZEND_ARG_OBJ_TYPE_MASK(0, collation, Stringable, MAY_BE_STRING|MAY_BE_NULL, "null")
8+
ZEND_ARG_OBJ_TYPE_MASK(0, hourCycle, Stringable, MAY_BE_STRING|MAY_BE_NULL, "null")
9+
ZEND_ARG_OBJ_TYPE_MASK(0, language, Stringable, MAY_BE_STRING|MAY_BE_NULL, "null")
10+
ZEND_ARG_OBJ_TYPE_MASK(0, numberingSystem, Stringable, MAY_BE_STRING|MAY_BE_NULL, "null")
11+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, numeric, _IS_BOOL, 1, "null")
12+
ZEND_ARG_OBJ_TYPE_MASK(0, region, Stringable, MAY_BE_STRING|MAY_BE_NULL, "null")
13+
ZEND_ARG_OBJ_TYPE_MASK(0, script, Stringable, MAY_BE_STRING|MAY_BE_NULL, "null")
14+
ZEND_END_ARG_INFO()
15+
16+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Ecma_Intl_Locale_Options_jsonSerialize, 0, 0, IS_OBJECT, 0)
17+
ZEND_END_ARG_INFO()
18+
19+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Ecma_Intl_Locale_Options_current, 0, 0, MAY_BE_STRING|MAY_BE_BOOL)
20+
ZEND_END_ARG_INFO()
21+
22+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Ecma_Intl_Locale_Options_next, 0, 0, IS_VOID, 0)
23+
ZEND_END_ARG_INFO()
24+
25+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Ecma_Intl_Locale_Options_key, 0, 0, IS_STRING, 0)
26+
ZEND_END_ARG_INFO()
27+
28+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Ecma_Intl_Locale_Options_valid, 0, 0, _IS_BOOL, 0)
29+
ZEND_END_ARG_INFO()
30+
31+
#define arginfo_class_Ecma_Intl_Locale_Options_rewind arginfo_class_Ecma_Intl_Locale_Options_next
32+
33+
34+
ZEND_METHOD(Ecma_Intl_Locale_Options, __construct);
35+
ZEND_METHOD(Ecma_Intl_Locale_Options, jsonSerialize);
36+
ZEND_METHOD(Ecma_Intl_Locale_Options, current);
37+
ZEND_METHOD(Ecma_Intl_Locale_Options, next);
38+
ZEND_METHOD(Ecma_Intl_Locale_Options, key);
39+
ZEND_METHOD(Ecma_Intl_Locale_Options, valid);
40+
ZEND_METHOD(Ecma_Intl_Locale_Options, rewind);
41+
42+
43+
static const zend_function_entry class_Ecma_Intl_Locale_Options_methods[] = {
44+
ZEND_ME(Ecma_Intl_Locale_Options, __construct, arginfo_class_Ecma_Intl_Locale_Options___construct, ZEND_ACC_PUBLIC)
45+
ZEND_ME(Ecma_Intl_Locale_Options, jsonSerialize, arginfo_class_Ecma_Intl_Locale_Options_jsonSerialize, ZEND_ACC_PUBLIC)
46+
ZEND_ME(Ecma_Intl_Locale_Options, current, arginfo_class_Ecma_Intl_Locale_Options_current, ZEND_ACC_PUBLIC)
47+
ZEND_ME(Ecma_Intl_Locale_Options, next, arginfo_class_Ecma_Intl_Locale_Options_next, ZEND_ACC_PUBLIC)
48+
ZEND_ME(Ecma_Intl_Locale_Options, key, arginfo_class_Ecma_Intl_Locale_Options_key, ZEND_ACC_PUBLIC)
49+
ZEND_ME(Ecma_Intl_Locale_Options, valid, arginfo_class_Ecma_Intl_Locale_Options_valid, ZEND_ACC_PUBLIC)
50+
ZEND_ME(Ecma_Intl_Locale_Options, rewind, arginfo_class_Ecma_Intl_Locale_Options_rewind, ZEND_ACC_PUBLIC)
51+
ZEND_FE_END
52+
};
53+
54+
static zend_class_entry *register_class_Ecma_Intl_Locale_Options(zend_class_entry *class_entry_Iterator, zend_class_entry *class_entry_JsonSerializable)
55+
{
56+
zend_class_entry ce, *class_entry;
57+
58+
INIT_NS_CLASS_ENTRY(ce, "Ecma\\Intl\\Locale", "Options", class_Ecma_Intl_Locale_Options_methods);
59+
class_entry = zend_register_internal_class_ex(&ce, NULL);
60+
class_entry->ce_flags |= ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_READONLY_CLASS;
61+
zend_class_implements(class_entry, 2, class_entry_Iterator, class_entry_JsonSerializable);
62+
63+
zval property_calendar_default_value;
64+
ZVAL_UNDEF(&property_calendar_default_value);
65+
zend_string *property_calendar_name = zend_string_init("calendar", sizeof("calendar") - 1, 1);
66+
zend_declare_typed_property(class_entry, property_calendar_name, &property_calendar_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
67+
zend_string_release(property_calendar_name);
68+
69+
zval property_caseFirst_default_value;
70+
ZVAL_UNDEF(&property_caseFirst_default_value);
71+
zend_string *property_caseFirst_name = zend_string_init("caseFirst", sizeof("caseFirst") - 1, 1);
72+
zend_declare_typed_property(class_entry, property_caseFirst_name, &property_caseFirst_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
73+
zend_string_release(property_caseFirst_name);
74+
75+
zval property_collation_default_value;
76+
ZVAL_UNDEF(&property_collation_default_value);
77+
zend_string *property_collation_name = zend_string_init("collation", sizeof("collation") - 1, 1);
78+
zend_declare_typed_property(class_entry, property_collation_name, &property_collation_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
79+
zend_string_release(property_collation_name);
80+
81+
zval property_hourCycle_default_value;
82+
ZVAL_UNDEF(&property_hourCycle_default_value);
83+
zend_string *property_hourCycle_name = zend_string_init("hourCycle", sizeof("hourCycle") - 1, 1);
84+
zend_declare_typed_property(class_entry, property_hourCycle_name, &property_hourCycle_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
85+
zend_string_release(property_hourCycle_name);
86+
87+
zval property_language_default_value;
88+
ZVAL_UNDEF(&property_language_default_value);
89+
zend_string *property_language_name = zend_string_init("language", sizeof("language") - 1, 1);
90+
zend_declare_typed_property(class_entry, property_language_name, &property_language_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
91+
zend_string_release(property_language_name);
92+
93+
zval property_numberingSystem_default_value;
94+
ZVAL_UNDEF(&property_numberingSystem_default_value);
95+
zend_string *property_numberingSystem_name = zend_string_init("numberingSystem", sizeof("numberingSystem") - 1, 1);
96+
zend_declare_typed_property(class_entry, property_numberingSystem_name, &property_numberingSystem_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
97+
zend_string_release(property_numberingSystem_name);
98+
99+
zval property_numeric_default_value;
100+
ZVAL_UNDEF(&property_numeric_default_value);
101+
zend_string *property_numeric_name = zend_string_init("numeric", sizeof("numeric") - 1, 1);
102+
zend_declare_typed_property(class_entry, property_numeric_name, &property_numeric_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL|MAY_BE_NULL));
103+
zend_string_release(property_numeric_name);
104+
105+
zval property_region_default_value;
106+
ZVAL_UNDEF(&property_region_default_value);
107+
zend_string *property_region_name = zend_string_init("region", sizeof("region") - 1, 1);
108+
zend_declare_typed_property(class_entry, property_region_name, &property_region_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
109+
zend_string_release(property_region_name);
110+
111+
zval property_script_default_value;
112+
ZVAL_UNDEF(&property_script_default_value);
113+
zend_string *property_script_name = zend_string_init("script", sizeof("script") - 1, 1);
114+
zend_declare_typed_property(class_entry, property_script_name, &property_script_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
115+
zend_string_release(property_script_name);
116+
117+
return class_entry;
118+
}

src/php/ecma_intl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ PHP_MINIT_FUNCTION(ecma_intl) {
5151
registerEcmaIntlCategory();
5252
registerEcmaIntlLocale();
5353
registerEcmaIntlLocaleCharacterDirection();
54-
registerEcmaIntlLocaleOptions();
54+
PHP_MINIT(ecma_intl_locale_options)(INIT_FUNC_ARGS_PASSTHRU);
5555
PHP_MINIT(ecma_intl_locale_textinfo)(INIT_FUNC_ARGS_PASSTHRU);
5656
PHP_MINIT(ecma_intl_locale_weekday)(INIT_FUNC_ARGS_PASSTHRU);
5757
PHP_MINIT(ecma_intl_locale_weekinfo)(INIT_FUNC_ARGS_PASSTHRU);

0 commit comments

Comments
 (0)