Skip to content

Add various stubs for Intl #4819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ext/intl/grapheme/grapheme.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

function grapheme_strlen(string $input): int|false|null {}

function grapheme_strpos(string $haystack, string $needle, int $offset = 0): int|false {}

function grapheme_stripos(string $haystack, string $needle, int $offset = 0): int|false {}

function grapheme_strrpos(string $haystack, string $needle, int $offset = 0): int|false {}

function grapheme_strripos(string $haystack, string $needle, int $offset = 0): int|false {}

function grapheme_substr(string $string, int $start, ?int $length = 0): string|false {}

function grapheme_strstr(string $haystack, string $needle, bool $before_needle = false): string|false {}

function grapheme_stristr(string $haystack, string $needle, bool $before_needle = false): string|false {}

function grapheme_extract(string $haystack, int $size, int $extract_type = GRAPHEME_EXTR_COUNT, int $start = 0, &$next = null): string|false {}
39 changes: 39 additions & 0 deletions ext/intl/grapheme/grapheme_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* This is a generated file, edit the .stub.php file instead. */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_strlen, 0, 1, MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_NULL)
ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_strpos, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_grapheme_stripos arginfo_grapheme_strpos

#define arginfo_grapheme_strrpos arginfo_grapheme_strpos

#define arginfo_grapheme_strripos arginfo_grapheme_strpos

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_substr, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_strstr, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, before_needle, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

#define arginfo_grapheme_stristr arginfo_grapheme_strstr

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_grapheme_extract, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, extract_type, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0)
ZEND_ARG_INFO(1, next)
ZEND_END_ARG_INFO()
5 changes: 5 additions & 0 deletions ext/intl/idn/idn.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

function idn_to_ascii(string $domain, int $options = 0, int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false {}

function idn_to_utf8(string $domain, int $options = 0, int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false {}
10 changes: 10 additions & 0 deletions ext/intl/idn/idn_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* This is a generated file, edit the .stub.php file instead. */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_idn_to_ascii, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, variant, IS_LONG, 0)
ZEND_ARG_INFO(1, idna_info)
ZEND_END_ARG_INFO()

#define arginfo_idn_to_utf8 arginfo_idn_to_ascii
23 changes: 23 additions & 0 deletions ext/intl/normalizer/normalizer.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

class Normalizer
{
/** @return string|false */
public static function normalize(string $input, int $form = Normalizer::FORM_C) {}

/** @return bool */
public static function isNormalized(string $input, int $form = Normalizer::FORM_C) {}

#if U_ICU_VERSION_MAJOR_NUM >= 56
/** @return string|null */
public static function getRawDecomposition(string $input, int $form = Normalizer::FORM_C) {}
#endif
}

function normalizer_normalize(string $input, int $form = Normalizer::FORM_C): string|false {}

function normalizer_is_normalized(string $input, int $form = Normalizer::FORM_C): bool {}

#if U_ICU_VERSION_MAJOR_NUM >= 56
function normalizer_get_raw_decomposition(string $input, int $form = Normalizer::FORM_C): ?string {}
#endif
32 changes: 32 additions & 0 deletions ext/intl/normalizer/normalizer_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* This is a generated file, edit the .stub.php file instead. */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Normalizer_normalize, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, form, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_Normalizer_isNormalized arginfo_class_Normalizer_normalize

#if U_ICU_VERSION_MAJOR_NUM >= 56
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Normalizer_getRawDecomposition, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, form, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_normalizer_normalize, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, form, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_normalizer_is_normalized, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, form, IS_LONG, 0)
ZEND_END_ARG_INFO()

#if U_ICU_VERSION_MAJOR_NUM >= 56
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_normalizer_get_raw_decomposition, 0, 1, IS_STRING, 1)
ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, form, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
22 changes: 4 additions & 18 deletions ext/intl/normalizer/normalizer_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "normalizer_class.h"
#include "php_intl.h"
#include "normalizer_normalize.h"
#include "normalizer_arginfo.h"
#include "intl_error.h"

#include <unicode/unorm.h>
Expand All @@ -25,30 +26,15 @@ zend_class_entry *Normalizer_ce_ptr = NULL;
* 'Normalizer' class registration structures & functions
*/

/* {{{ Normalizer methods arguments info */

ZEND_BEGIN_ARG_INFO_EX( normalizer_args, 0, 0, 1 )
ZEND_ARG_INFO( 0, input )
ZEND_ARG_INFO( 0, form )
ZEND_END_ARG_INFO()

#if U_ICU_VERSION_MAJOR_NUM >= 56
ZEND_BEGIN_ARG_INFO_EX( decomposition_args, 0, 0, 1 )
ZEND_ARG_INFO( 0, input )
ZEND_END_ARG_INFO();
#endif

/* }}} */

/* {{{ Normalizer_class_functions
* Every 'Normalizer' class method has an entry in this table
*/

static const zend_function_entry Normalizer_class_functions[] = {
ZEND_FENTRY( normalize, ZEND_FN( normalizer_normalize ), normalizer_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
ZEND_FENTRY( isNormalized, ZEND_FN( normalizer_is_normalized ), normalizer_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
ZEND_FENTRY( normalize, ZEND_FN( normalizer_normalize ), arginfo_class_Normalizer_normalize, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
ZEND_FENTRY( isNormalized, ZEND_FN( normalizer_is_normalized ), arginfo_class_Normalizer_isNormalized, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
#if U_ICU_VERSION_MAJOR_NUM >= 56
ZEND_FENTRY( getRawDecomposition, ZEND_FN( normalizer_get_raw_decomposition ), decomposition_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
ZEND_FENTRY( getRawDecomposition, ZEND_FN( normalizer_get_raw_decomposition ), arginfo_class_Normalizer_getRawDecomposition, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
#endif
PHP_FE_END
};
Expand Down
118 changes: 23 additions & 95 deletions ext/intl/php_intl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "formatter/formatter_parse.h"

#include "grapheme/grapheme.h"
#include "grapheme/grapheme_arginfo.h"

#include "msgformat/msgformat.h"
#include "msgformat/msgformat_class.h"
Expand All @@ -52,6 +53,7 @@
#include "normalizer/normalizer.h"
#include "normalizer/normalizer_class.h"
#include "normalizer/normalizer_normalize.h"
#include "normalizer/normalizer_arginfo.h"

#include "locale/locale.h"
#include "locale/locale_class.h"
Expand All @@ -68,6 +70,7 @@
#include "dateformat/dateformat_data.h"

#include "resourcebundle/resourcebundle_class.h"
#include "resourcebundle/resourcebundle_arginfo.h"

#include "transliterator/transliterator.h"
#include "transliterator/transliterator_class.h"
Expand All @@ -85,6 +88,7 @@
#include "breakiterator/breakiterator_iterators.h"

#include "idn/idn.h"
#include "idn/idn_arginfo.h"
#include "uchar/uchar.h"

# include "spoofchecker/spoofchecker_class.h"
Expand Down Expand Up @@ -173,47 +177,6 @@ ZEND_END_ARG_INFO()
#define intl_0_args collator_static_0_args
#define intl_1_arg collator_static_1_arg

ZEND_BEGIN_ARG_INFO_EX(normalizer_args, 0, 0, 1)
ZEND_ARG_INFO(0, input)
ZEND_ARG_INFO(0, form)
ZEND_END_ARG_INFO()

#if U_ICU_VERSION_MAJOR_NUM >= 56
ZEND_BEGIN_ARG_INFO_EX(decomposition_args, 0, 0, 1)
ZEND_ARG_INFO(0, input)
ZEND_END_ARG_INFO();
#endif

ZEND_BEGIN_ARG_INFO_EX(grapheme_1_arg, 0, 0, 1)
ZEND_ARG_INFO(0, string)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(grapheme_search_args, 0, 0, 2)
ZEND_ARG_INFO(0, haystack)
ZEND_ARG_INFO(0, needle)
ZEND_ARG_INFO(0, offset)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(grapheme_substr_args, 0, 0, 2)
ZEND_ARG_INFO(0, string)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, length)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(grapheme_strstr_args, 0, 0, 2)
ZEND_ARG_INFO(0, haystack)
ZEND_ARG_INFO(0, needle)
ZEND_ARG_INFO(0, before_needle)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(grapheme_extract_args, 0, 0, 2)
ZEND_ARG_INFO(0, arg1)
ZEND_ARG_INFO(0, arg2)
ZEND_ARG_INFO(0, arg3)
ZEND_ARG_INFO(0, arg4)
ZEND_ARG_INFO(1, arg5) /* 1 = pass by reference */
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(datefmt_parse_args, 0, 0, 2)
ZEND_ARG_INFO(0, formatter)
ZEND_ARG_INFO(0, string)
Expand Down Expand Up @@ -349,41 +312,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_datefmt_create, 0, 0, 3)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_idn_to_ascii, 0, 0, 1)
ZEND_ARG_INFO(0, domain)
ZEND_ARG_INFO(0, option)
ZEND_ARG_INFO(0, variant)
ZEND_ARG_INFO(1, idn_info)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( arginfo_resourcebundle_create_proc, 0, 0, 2 )
ZEND_ARG_INFO( 0, locale )
ZEND_ARG_INFO( 0, bundlename )
ZEND_ARG_INFO( 0, fallback )
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( arginfo_resourcebundle_get_proc, 0, 0, 2 )
ZEND_ARG_INFO( 0, bundle )
ZEND_ARG_INFO( 0, index )
ZEND_ARG_INFO( 0, fallback )
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( arginfo_resourcebundle_count_proc, 0, 0, 1 )
ZEND_ARG_INFO( 0, bundle )
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( arginfo_resourcebundle_locales_proc, 0, 0, 1 )
ZEND_ARG_INFO( 0, bundlename )
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( arginfo_resourcebundle_get_error_code_proc, 0, 0, 1 )
ZEND_ARG_INFO( 0, bundle )
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( arginfo_resourcebundle_get_error_message_proc, 0, 0, 1 )
ZEND_ARG_INFO( 0, bundle )
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( arginfo_transliterator_void, 0, 0, 0 )
ZEND_END_ARG_INFO()

Expand Down Expand Up @@ -583,10 +511,10 @@ static const zend_function_entry intl_functions[] = {
PHP_FE( numfmt_get_error_message, arginfo_numfmt_get_error_code )

/* normalizer functions */
PHP_FE( normalizer_normalize, normalizer_args )
PHP_FE( normalizer_is_normalized, normalizer_args )
PHP_FE( normalizer_normalize, arginfo_normalizer_normalize )
PHP_FE( normalizer_is_normalized, arginfo_normalizer_is_normalized )
#if U_ICU_VERSION_MAJOR_NUM >= 56
PHP_FE( normalizer_get_raw_decomposition, decomposition_args )
PHP_FE( normalizer_get_raw_decomposition, arginfo_normalizer_get_raw_decomposition )
#endif

/* Locale functions */
Expand Down Expand Up @@ -644,27 +572,27 @@ static const zend_function_entry intl_functions[] = {
PHP_FE( datefmt_get_error_message, arginfo_msgfmt_get_error_message )

/* grapheme functions */
PHP_FE( grapheme_strlen, grapheme_1_arg )
PHP_FE( grapheme_strpos, grapheme_search_args )
PHP_FE( grapheme_stripos, grapheme_search_args )
PHP_FE( grapheme_strrpos, grapheme_search_args )
PHP_FE( grapheme_strripos, grapheme_search_args )
PHP_FE( grapheme_substr, grapheme_substr_args )
PHP_FE( grapheme_strstr, grapheme_strstr_args )
PHP_FE( grapheme_stristr, grapheme_strstr_args )
PHP_FE( grapheme_extract, grapheme_extract_args )
PHP_FE( grapheme_strlen, arginfo_grapheme_strlen )
PHP_FE( grapheme_strpos, arginfo_grapheme_strpos )
PHP_FE( grapheme_stripos, arginfo_grapheme_stripos )
PHP_FE( grapheme_strrpos, arginfo_grapheme_strrpos )
PHP_FE( grapheme_strripos, arginfo_grapheme_strripos )
PHP_FE( grapheme_substr, arginfo_grapheme_substr )
PHP_FE( grapheme_strstr, arginfo_grapheme_strstr )
PHP_FE( grapheme_stristr, arginfo_grapheme_stristr )
PHP_FE( grapheme_extract, arginfo_grapheme_extract )

/* IDN functions */
PHP_FE( idn_to_ascii, arginfo_idn_to_ascii)
PHP_FE( idn_to_utf8, arginfo_idn_to_ascii)
PHP_FE( idn_to_utf8, arginfo_idn_to_utf8)

/* ResourceBundle functions */
PHP_FE( resourcebundle_create, arginfo_resourcebundle_create_proc )
PHP_FE( resourcebundle_get, arginfo_resourcebundle_get_proc )
PHP_FE( resourcebundle_count, arginfo_resourcebundle_count_proc )
PHP_FE( resourcebundle_locales, arginfo_resourcebundle_locales_proc )
PHP_FE( resourcebundle_get_error_code, arginfo_resourcebundle_get_error_code_proc )
PHP_FE( resourcebundle_get_error_message, arginfo_resourcebundle_get_error_message_proc )
PHP_FE( resourcebundle_create, arginfo_resourcebundle_create )
PHP_FE( resourcebundle_get, arginfo_resourcebundle_get )
PHP_FE( resourcebundle_count, arginfo_resourcebundle_count )
PHP_FE( resourcebundle_locales, arginfo_resourcebundle_locales )
PHP_FE( resourcebundle_get_error_code, arginfo_resourcebundle_get_error_code )
PHP_FE( resourcebundle_get_error_message, arginfo_resourcebundle_get_error_message )

/* Transliterator functions */
PHP_FE( transliterator_create, arginfo_transliterator_create )
Expand Down
43 changes: 43 additions & 0 deletions ext/intl/resourcebundle/resourcebundle.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

class ResourceBundle implements Traversable
{
public function __construct(?string $locale, ?string $bundlename, bool $fallback = true) {}

/** @return ResourceBundle|null */
public static function create(?string $locale, ?string $bundlename, bool $fallback = true) {}

/**
* @param string|int $index
* @return mixed
*/
public function get($index, bool $fallback = true) {}

/** @return int|false */
public function count() {}

/** @return array|false */
public static function getLocales(string $bundlename) {}

/** @return int */
public function getErrorCode() {}

/** @return string */
public function getErrorMessage() {}
}

function resourcebundle_create(?string $locale, ?string $bundlename, bool $fallback = true): ?ResourceBundle {}

/**
* @param string|int $index
* @return mixed
*/
function resourcebundle_get(ResourceBundle $bundle, $index) {}

function resourcebundle_count(ResourceBundle $bundle): int|false {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should convert the "unconstructed" case into a hard Error exception in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like this change! Will provide a PR sometime soon.


function resourcebundle_locales(string $bundlename): array|false {}

function resourcebundle_get_error_code(ResourceBundle $bundle): int {}

function resourcebundle_get_error_message(ResourceBundle $bundle): string {}
Loading