Skip to content

Convert enchant resources to opaque objects #5577

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
300 changes: 159 additions & 141 deletions ext/enchant/enchant.c

Large diffs are not rendered by default.

96 changes: 36 additions & 60 deletions ext/enchant/enchant.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,70 @@

/** @generate-function-entries */

/** @return resource|false */
function enchant_broker_init() {}
final class EnchantBroker
{
}

/** @param resource $broker */
function enchant_broker_free($broker): bool {}
final class EnchantDict
Copy link
Member Author

Choose a reason for hiding this comment

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

Could we use EnchantDictionary instead? The usage of the Dict abbreviation doesn't seem to fit PHP's recent naming strategy.

Copy link
Member

Choose a reason for hiding this comment

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

I'm okay either way.

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 used EnchantDictionary

{
}

/**
* @param resource $broker
* @return string|false
*/
function enchant_broker_get_error($broker) {}
function enchant_broker_init(): EnchantBroker|false {}

/**
* @param resource $broker
* @deprecated
*/
function enchant_broker_set_dict_path($broker, int $name, string $value): bool {}
/** @deprecated */
function enchant_broker_free(EnchantBroker $broker): bool {}

/**
* @param resource $broker
* @deprecated
*/
function enchant_broker_get_dict_path($broker, int $name): string|false {}
function enchant_broker_get_error(EnchantBroker $broker): string|false {}

/** @param resource $broker */
function enchant_broker_list_dicts($broker): array {}
/** @deprecated */
function enchant_broker_set_dict_path(EnchantBroker $broker, int $name, string $value): bool {}

/**
* @param resource $broker
* @return resource|false
*/
function enchant_broker_request_dict($broker, string $tag) {}
/** @deprecated */
function enchant_broker_get_dict_path(EnchantBroker $broker, int $name): string|false {}

/**
* @param resource $broker
* @return resource|false
*/
function enchant_broker_request_pwl_dict($broker, string $filename) {}
function enchant_broker_list_dicts(EnchantBroker $broker): array {}

function enchant_broker_request_dict(EnchantBroker $broker, string $tag): EnchantDict|false {}

/** @param resource $dict */
function enchant_broker_free_dict($dict): bool {}
function enchant_broker_request_pwl_dict(EnchantBroker $broker, string $filename): EnchantDict|false {}

/** @param resource $broker */
function enchant_broker_dict_exists($broker, string $tag): bool {}
/** @deprecated */
function enchant_broker_free_dict(EnchantDict $dict): bool {}

/** @param resource $broker */
function enchant_broker_set_ordering($broker, string $tag, string $ordering): bool {}
function enchant_broker_dict_exists(EnchantBroker $broker, string $tag): bool {}

/** @param resource $broker */
function enchant_broker_describe($broker): array {}
function enchant_broker_set_ordering(EnchantBroker $broker, string $tag, string $ordering): bool {}

/** @param resource $dict */
function enchant_dict_quick_check($dict, string $word, &$suggestions = null): bool {}
function enchant_broker_describe(EnchantBroker $broker): array {}

/** @param resource $dict */
function enchant_dict_check($dict, string $word): bool {}
function enchant_dict_quick_check(EnchantDict $dict, string $word, &$suggestions = null): bool {}

/** @param resource $dict */
function enchant_dict_suggest($dict, string $word): array {}
function enchant_dict_check(EnchantDict $dict, string $word): bool {}

/** @param resource $dict */
function enchant_dict_add($dict, string $word): void {}
function enchant_dict_suggest(EnchantDict $dict, string $word): array {}

function enchant_dict_add(EnchantDict $dict, string $word): void {}

/**
* @param resource $dict
* @alias enchant_dict_add
* @deprecated
*/
function enchant_dict_add_to_personal($dict, string $word): void {}
function enchant_dict_add_to_personal(EnchantDict $dict, string $word): void {}

/** @param resource $dict */
function enchant_dict_add_to_session($dict, string $word): void {}
function enchant_dict_add_to_session(EnchantDict $dict, string $word): void {}

/** @param resource $dict */
function enchant_dict_is_added($dict, string $word): bool {}
function enchant_dict_is_added(EnchantDict $dict, string $word): bool {}

/**
* @param resource $dict
* @alias enchant_dict_is_added
* @deprecated
*/
function enchant_dict_is_in_session($dict, string $word): bool {}
function enchant_dict_is_in_session(EnchantDict $dict, string $word): bool {}

function enchant_dict_store_replacement(EnchantDict $dict, string $mis, string $cor): void {}

/** @param resource $dict */
function enchant_dict_store_replacement($dict, string $mis, string $cor): void {}
function enchant_dict_get_error(EnchantDict $dict): string|false {}

/** @param resource $dict */
function enchant_dict_get_error($dict): string|false {}
function enchant_dict_describe(EnchantDict $dict): array {}

/** @param resource $dict */
function enchant_dict_describe($dict): array {}
56 changes: 33 additions & 23 deletions ext/enchant/enchant_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
/* This is a generated file, edit the .stub.php file instead. */

ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_init, 0, 0, 0)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_enchant_broker_init, 0, 0, EnchantBroker, MAY_BE_FALSE)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_free, 0, 1, _IS_BOOL, 0)
ZEND_ARG_INFO(0, broker)
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_get_error, 0, 0, 1)
ZEND_ARG_INFO(0, broker)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_enchant_broker_get_error, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_set_dict_path, 0, 3, _IS_BOOL, 0)
ZEND_ARG_INFO(0, broker)
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
ZEND_ARG_TYPE_INFO(0, name, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_enchant_broker_get_dict_path, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_INFO(0, broker)
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
ZEND_ARG_TYPE_INFO(0, name, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_list_dicts, 0, 1, IS_ARRAY, 0)
ZEND_ARG_INFO(0, broker)
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_request_dict, 0, 0, 2)
ZEND_ARG_INFO(0, broker)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_enchant_broker_request_dict, 0, 2, EnchantDict, MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
ZEND_ARG_TYPE_INFO(0, tag, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_request_pwl_dict, 0, 0, 2)
ZEND_ARG_INFO(0, broker)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_enchant_broker_request_pwl_dict, 0, 2, EnchantDict, MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_free_dict, 0, 1, _IS_BOOL, 0)
ZEND_ARG_INFO(0, dict)
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_dict_exists, 0, 2, _IS_BOOL, 0)
ZEND_ARG_INFO(0, broker)
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
ZEND_ARG_TYPE_INFO(0, tag, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_set_ordering, 0, 3, _IS_BOOL, 0)
ZEND_ARG_INFO(0, broker)
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
ZEND_ARG_TYPE_INFO(0, tag, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, ordering, IS_STRING, 0)
ZEND_END_ARG_INFO()

#define arginfo_enchant_broker_describe arginfo_enchant_broker_list_dicts

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_quick_check, 0, 2, _IS_BOOL, 0)
ZEND_ARG_INFO(0, dict)
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, suggestions, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_check, 0, 2, _IS_BOOL, 0)
ZEND_ARG_INFO(0, dict)
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_suggest, 0, 2, IS_ARRAY, 0)
ZEND_ARG_INFO(0, dict)
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_add, 0, 2, IS_VOID, 0)
ZEND_ARG_INFO(0, dict)
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
ZEND_END_ARG_INFO()

Expand All @@ -83,17 +83,17 @@ ZEND_END_ARG_INFO()
#define arginfo_enchant_dict_is_in_session arginfo_enchant_dict_check

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_store_replacement, 0, 3, IS_VOID, 0)
ZEND_ARG_INFO(0, dict)
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
ZEND_ARG_TYPE_INFO(0, mis, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, cor, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_enchant_dict_get_error, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_INFO(0, dict)
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_describe, 0, 1, IS_ARRAY, 0)
ZEND_ARG_INFO(0, dict)
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
ZEND_END_ARG_INFO()


Expand Down Expand Up @@ -122,14 +122,14 @@ ZEND_FUNCTION(enchant_dict_describe);

static const zend_function_entry ext_functions[] = {
ZEND_FE(enchant_broker_init, arginfo_enchant_broker_init)
ZEND_FE(enchant_broker_free, arginfo_enchant_broker_free)
ZEND_DEP_FE(enchant_broker_free, arginfo_enchant_broker_free)
ZEND_FE(enchant_broker_get_error, arginfo_enchant_broker_get_error)
ZEND_DEP_FE(enchant_broker_set_dict_path, arginfo_enchant_broker_set_dict_path)
ZEND_DEP_FE(enchant_broker_get_dict_path, arginfo_enchant_broker_get_dict_path)
ZEND_FE(enchant_broker_list_dicts, arginfo_enchant_broker_list_dicts)
ZEND_FE(enchant_broker_request_dict, arginfo_enchant_broker_request_dict)
ZEND_FE(enchant_broker_request_pwl_dict, arginfo_enchant_broker_request_pwl_dict)
ZEND_FE(enchant_broker_free_dict, arginfo_enchant_broker_free_dict)
ZEND_DEP_FE(enchant_broker_free_dict, arginfo_enchant_broker_free_dict)
ZEND_FE(enchant_broker_dict_exists, arginfo_enchant_broker_dict_exists)
ZEND_FE(enchant_broker_set_ordering, arginfo_enchant_broker_set_ordering)
ZEND_FE(enchant_broker_describe, arginfo_enchant_broker_describe)
Expand All @@ -146,3 +146,13 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(enchant_dict_describe, arginfo_enchant_dict_describe)
ZEND_FE_END
};


static const zend_function_entry class_EnchantBroker_methods[] = {
ZEND_FE_END
};


static const zend_function_entry class_EnchantDict_methods[] = {
ZEND_FE_END
};
6 changes: 3 additions & 3 deletions ext/enchant/tests/broker_describe.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ if (!$broker) {
}

if (!enchant_broker_describe($broker)) {
enchant_broker_free($broker);
@enchant_broker_free($broker);

echo "skip: No broker providers found\n";
}

enchant_broker_free($broker);
@enchant_broker_free($broker);
?>
--FILE--
<?php
Expand All @@ -47,7 +47,7 @@ if($broker) {
echo "failed, brocker describe array \n";
}

enchant_broker_free($broker);
@enchant_broker_free($broker);

} else {
echo("failed, broker_init failure\n");
Expand Down
2 changes: 1 addition & 1 deletion ext/enchant/tests/broker_dict_exists.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ marcosptf - <marcosptf@yahoo.com.br>
--SKIPIF--
<?php
if(!extension_loaded('enchant')) die('skip, enchant not loader');
if (!is_resource(enchant_broker_init())) {die("skip, resource dont load\n");}
if (!is_object(enchant_broker_init())) {die("skip, resource dont load\n");}
if (!is_array(enchant_broker_list_dicts(enchant_broker_init()))) {die("skip, no dictionary installed on this machine! \n");}
?>
--FILE--
Expand Down
8 changes: 5 additions & 3 deletions ext/enchant/tests/broker_free.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ marcosptf - <marcosptf@yahoo.com.br>
--SKIPIF--
<?php
if(!extension_loaded('enchant')) die('skip, enchant not loader');
if (!is_resource(enchant_broker_init())) {die("skip, resource dont load\n");}
if (!is_object(enchant_broker_init())) {die("skip, resource dont load\n");}
?>
--FILE--
<?php
$broker = enchant_broker_init();
if (is_resource($broker)) {
if (is_object($broker)) {
echo "OK\n";
enchant_broker_free($broker);

Expand All @@ -19,6 +19,8 @@ if (is_resource($broker)) {
}
echo "OK\n";
?>
--EXPECT--
--EXPECTF--
OK

Deprecated: Function enchant_broker_free() is deprecated in %s
OK
8 changes: 4 additions & 4 deletions ext/enchant/tests/broker_free_01.phpt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
--TEST--
enchant_broker_free() function
@enchant_broker_free() function
--CREDITS--
marcosptf - <marcosptf@yahoo.com.br>
--SKIPIF--
<?php
if(!extension_loaded('enchant')) die('skip, enchant not loader');
if (!is_resource(enchant_broker_init())) {die("skip, resource dont load\n");}
if (!is_object(enchant_broker_init())) {die("skip, resource dont load\n");}
?>
--FILE--
<?php
$broker = enchant_broker_init();
if (is_resource($broker)) {
if (is_object($broker)) {
echo("OK\n");

if (enchant_broker_free($broker)) {
if (@enchant_broker_free($broker)) {
echo("OK\n");
} else {
echo("broker free failed\n");
Expand Down
10 changes: 5 additions & 5 deletions ext/enchant/tests/broker_free_02.phpt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--TEST--
enchant_broker_free() function
@enchant_broker_free() function
--CREDITS--
marcosptf - <marcosptf@yahoo.com.br>
--SKIPIF--
<?php
if(!extension_loaded('enchant')) die('skip, enchant not loader');
if(!is_resource(enchant_broker_init())) {die("skip, resource dont load\n");}
if(!is_object(enchant_broker_init())) {die("skip, resource dont load\n");}
if(!is_array(enchant_broker_list_dicts(enchant_broker_init()))) {die("skip, no dictionary installed on this machine! \n");}
?>
--FILE--
Expand All @@ -14,7 +14,7 @@ $broker = enchant_broker_init();
$dicts = enchant_broker_list_dicts($broker);
$newWord = array("iLoveJava","iLoveJavascript","iLoveRuby","iLovePerl","iLoveAwk","iLoveC");

if (is_resource($broker)) {
if (is_object($broker)) {
echo("OK\n");
$requestDict = enchant_broker_request_dict($broker, $dicts[0]['lang_tag']);

Expand All @@ -27,10 +27,10 @@ if (is_resource($broker)) {
if (NULL === $AddtoPersonalDict) {
var_dump($AddtoPersonalDict);

if (enchant_broker_free_dict($requestDict)) {
if (@enchant_broker_free_dict($requestDict)) {
echo("OK\n");

if (enchant_broker_free($broker)) {
if (@enchant_broker_free($broker)) {
echo("OK\n");

} else {
Expand Down
Loading