Skip to content

Add various stubs for Intl - part 2 #4826

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 1 commit 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
71 changes: 71 additions & 0 deletions ext/intl/collator/collator.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

class Collator
{
public function __construct(string $locale) {}

/** @return Collator|null */
public static function create(string $locale) {}

/** @return int|false */
public function compare(string $str1, string $str2) {}

/** @return bool */
public function sort(array &$arr, $sort_flag = Collator::SORT_REGULAR) {}

/** @return bool */
public function sortWithSortKeys(array &$arr) {}

/** @return bool */
public function asort(array &$arr, int $sort_flag = Collator::SORT_REGULAR) {}

/** @return int|false */
public function getAttribute(int $attr) {}

/** @return bool */
public function setAttribute(int $attr, int $val) {}

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

/** @return bool */
public function setStrength(int $strength) {}

/** @return string|false */
public function getLocale(int $type) {}

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

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

/** @return string|false */
public function getSortKey(string $str) {}
}

function collator_create(string $locale): ?Collator {}

function collator_compare(Collator $object, string $str1, string $str2): int|false {}

function collator_get_attribute(Collator $object, int $attr): int|false {}

function collator_set_attribute(Collator $object, int $attr, int $val): bool {}

function collator_get_strength(Collator $object): int {}

function collator_set_strength(Collator $object, int $strength): bool {}

function collator_sort(Collator $object, array &$arr, int $sort_flag = Collator::SORT_REGULAR): bool {}

function collator_sort_with_sort_keys(Collator $object, array &$arr): bool {}

function collator_asort(Collator $object, array &$arr, int $sort_flag = Collator::SORT_REGULAR): bool {}

function collator_get_locale(Collator $object, int $type): string|false {}

function collator_get_error_code(Collator $object): int|false {}

function collator_get_error_message(Collator $object): string|false {}

function collator_get_sort_key(Collator $object, string $str): string|false {}
115 changes: 115 additions & 0 deletions ext/intl/collator/collator_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* This is a generated file, edit the .stub.php file instead. */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_Collator_create arginfo_class_Collator___construct

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator_compare, 0, 0, 2)
ZEND_ARG_TYPE_INFO(0, str1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, str2, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator_sort, 0, 0, 1)
ZEND_ARG_TYPE_INFO(1, arr, IS_ARRAY, 0)
ZEND_ARG_INFO(0, sort_flag)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator_sortWithSortKeys, 0, 0, 1)
ZEND_ARG_TYPE_INFO(1, arr, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator_asort, 0, 0, 1)
ZEND_ARG_TYPE_INFO(1, arr, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, sort_flag, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator_getAttribute, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator_setAttribute, 0, 0, 2)
ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, val, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator_getStrength, 0, 0, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator_setStrength, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, strength, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator_getLocale, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_Collator_getErrorCode arginfo_class_Collator_getStrength

#define arginfo_class_Collator_getErrorMessage arginfo_class_Collator_getStrength

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator_getSortKey, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_collator_create, 0, 1, Collator, 1)
ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_compare, 0, 3, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_TYPE_INFO(0, str1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, str2, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_get_attribute, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_collator_set_attribute, 0, 3, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, val, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_collator_get_strength, 0, 1, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_collator_set_strength, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_TYPE_INFO(0, strength, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_collator_sort, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_TYPE_INFO(1, arr, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, sort_flag, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_collator_sort_with_sort_keys, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_TYPE_INFO(1, arr, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

#define arginfo_collator_asort arginfo_collator_sort

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_get_locale, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_get_error_code, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_get_error_message, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_get_sort_key, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_END_ARG_INFO()
57 changes: 15 additions & 42 deletions ext/intl/collator/collator_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "collator_locale.h"
#include "collator_create.h"
#include "collator_error.h"
#include "collator_arginfo.h"
#include "intl_error.h"

#include <unicode/ucol.h>
Expand Down Expand Up @@ -62,53 +63,25 @@ zend_object *Collator_object_create(zend_class_entry *ce )
* 'Collator' class registration structures & functions
*/

/* {{{ Collator methods arguments info */
/* NOTE: modifying 'collator_XX_args' do not forget to
modify approptiate 'collator_XX_args' for
the procedural API.
*/
ZEND_BEGIN_ARG_INFO_EX( collator_0_args, 0, 0, 0 )
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( collator_1_arg, 0, 0, 1 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( collator_2_args, 0, 0, 2 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_ARG_INFO( 0, arg2 )
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( collator_sort_args, 0, 0, 1 )
ZEND_ARG_ARRAY_INFO( 1, arr, 0 )
ZEND_ARG_INFO( 0, flags )
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX( collator_sort_with_sort_keys_args, 0, 0, 1 )
ZEND_ARG_ARRAY_INFO( 1, arr, 0 )
ZEND_END_ARG_INFO()

/* }}} */

/* {{{ Collator_class_functions
* Every 'Collator' class method has an entry in this table
*/

static const zend_function_entry Collator_class_functions[] = {
PHP_ME( Collator, __construct, collator_1_arg, ZEND_ACC_PUBLIC )
ZEND_FENTRY( create, ZEND_FN( collator_create ), collator_1_arg, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( compare, ZEND_FN( collator_compare ), collator_2_args )
PHP_NAMED_FE( sort, ZEND_FN( collator_sort ), collator_sort_args )
PHP_NAMED_FE( sortWithSortKeys, ZEND_FN( collator_sort_with_sort_keys ), collator_sort_with_sort_keys_args )
PHP_NAMED_FE( asort, ZEND_FN( collator_asort ), collator_sort_args )
PHP_NAMED_FE( getAttribute, ZEND_FN( collator_get_attribute ), collator_1_arg )
PHP_NAMED_FE( setAttribute, ZEND_FN( collator_set_attribute ), collator_2_args )
PHP_NAMED_FE( getStrength, ZEND_FN( collator_get_strength ), collator_0_args )
PHP_NAMED_FE( setStrength, ZEND_FN( collator_set_strength ), collator_1_arg )
PHP_NAMED_FE( getLocale, ZEND_FN( collator_get_locale ), collator_1_arg )
PHP_NAMED_FE( getErrorCode, ZEND_FN( collator_get_error_code ), collator_0_args )
PHP_NAMED_FE( getErrorMessage, ZEND_FN( collator_get_error_message ), collator_0_args )
PHP_NAMED_FE( getSortKey, ZEND_FN( collator_get_sort_key ), collator_1_arg )
PHP_ME( Collator, __construct, arginfo_class_Collator___construct, ZEND_ACC_PUBLIC )
ZEND_FENTRY( create, ZEND_FN( collator_create ), arginfo_class_Collator_create, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( compare, ZEND_FN( collator_compare ), arginfo_class_Collator_compare )
PHP_NAMED_FE( sort, ZEND_FN( collator_sort ), arginfo_class_Collator_sort )
PHP_NAMED_FE( sortWithSortKeys, ZEND_FN( collator_sort_with_sort_keys ), arginfo_class_Collator_sortWithSortKeys )
PHP_NAMED_FE( asort, ZEND_FN( collator_asort ), arginfo_class_Collator_asort )
PHP_NAMED_FE( getAttribute, ZEND_FN( collator_get_attribute ), arginfo_class_Collator_getAttribute )
PHP_NAMED_FE( setAttribute, ZEND_FN( collator_set_attribute ), arginfo_class_Collator_setAttribute )
PHP_NAMED_FE( getStrength, ZEND_FN( collator_get_strength ), arginfo_class_Collator_getStrength )
PHP_NAMED_FE( setStrength, ZEND_FN( collator_set_strength ), arginfo_class_Collator_setStrength )
PHP_NAMED_FE( getLocale, ZEND_FN( collator_get_locale ), arginfo_class_Collator_getLocale )
PHP_NAMED_FE( getErrorCode, ZEND_FN( collator_get_error_code ), arginfo_class_Collator_getErrorCode )
PHP_NAMED_FE( getErrorMessage, ZEND_FN( collator_get_error_message ), arginfo_class_Collator_getErrorMessage )
PHP_NAMED_FE( getSortKey, ZEND_FN( collator_get_sort_key ), arginfo_class_Collator_getSortKey )
PHP_FE_END
};
/* }}} */
Expand Down
22 changes: 22 additions & 0 deletions ext/intl/common/common.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

class IntlIterator implements Iterator
Copy link
Member

Choose a reason for hiding this comment

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

TIL. I wanted to add this as general core functionality, didn't know it exists in intl.

{
public function current() {}

public function key() {}

public function next() {}

public function rewind() {}

public function valid() {}
}

function intl_get_error_code(): int {}

function intl_get_error_message(): string {}

function intl_is_failure(int $error_code): bool {}

function intl_error_name(int $error_code): string {}
26 changes: 26 additions & 0 deletions ext/intl/common/common_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* This is a generated file, edit the .stub.php file instead. */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlIterator_current, 0, 0, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_IntlIterator_key arginfo_class_IntlIterator_current

#define arginfo_class_IntlIterator_next arginfo_class_IntlIterator_current

#define arginfo_class_IntlIterator_rewind arginfo_class_IntlIterator_current

#define arginfo_class_IntlIterator_valid arginfo_class_IntlIterator_current

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intl_get_error_code, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intl_get_error_message, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intl_is_failure, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, error_code, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intl_error_name, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, error_code, IS_LONG, 0)
ZEND_END_ARG_INFO()
14 changes: 6 additions & 8 deletions ext/intl/common/common_enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <stdio.h>

#include "common_enum.h"
#include "common_arginfo.h"

extern "C" {
#include <zend_interfaces.h>
Expand Down Expand Up @@ -280,15 +281,12 @@ static PHP_METHOD(IntlIterator, valid)
RETURN_BOOL(ii->iterator->funcs->valid(ii->iterator) == SUCCESS);
}

ZEND_BEGIN_ARG_INFO_EX(ainfo_se_void, 0, 0, 0)
ZEND_END_ARG_INFO()

static const zend_function_entry IntlIterator_class_functions[] = {
PHP_ME(IntlIterator, current, ainfo_se_void, ZEND_ACC_PUBLIC)
PHP_ME(IntlIterator, key, ainfo_se_void, ZEND_ACC_PUBLIC)
PHP_ME(IntlIterator, next, ainfo_se_void, ZEND_ACC_PUBLIC)
PHP_ME(IntlIterator, rewind, ainfo_se_void, ZEND_ACC_PUBLIC)
PHP_ME(IntlIterator, valid, ainfo_se_void, ZEND_ACC_PUBLIC)
PHP_ME(IntlIterator, current, arginfo_class_IntlIterator_current, ZEND_ACC_PUBLIC)
PHP_ME(IntlIterator, key, arginfo_class_IntlIterator_key, ZEND_ACC_PUBLIC)
PHP_ME(IntlIterator, next, arginfo_class_IntlIterator_next, ZEND_ACC_PUBLIC)
PHP_ME(IntlIterator, rewind, arginfo_class_IntlIterator_rewind, ZEND_ACC_PUBLIC)
PHP_ME(IntlIterator, valid, arginfo_class_IntlIterator_valid, ZEND_ACC_PUBLIC)
PHP_FE_END
};

Expand Down
Loading