Move resource-object classes of PSpell to \PSpell namespace

[namespaces in bundled extensions](https://wiki.php.net/rfc/namespaces_in_bundled_extensions) changes for PSpell.

 - Rename `PSpell` class to `\PSpell\Dictionary`
 - Rename `PSpellConfig` class to `\PSpell\Config`
 - Add entries to `UPGRADING` file.

Related: bd12c94f
This commit is contained in:
Ayesh Karunaratne 2021-05-10 20:40:19 +05:30 committed by Nikita Popov
parent 3ccc0409ce
commit 57a635c655
6 changed files with 67 additions and 52 deletions

4
NEWS
View File

@ -99,8 +99,8 @@ PHP NEWS
. Fixed bug #38334 (Proper data-type support for PDO_SQLITE). (Nikita)
- PSpell:
. Convert resource<pspell> to object \PSpell. (Sara)
. Convert resource<pspell config> to object \PSpellConfig. (Sara)
. Convert resource<pspell> to object \PSpell\Dictionary. (Sara)
. Convert resource<pspell config> to object \PSpell\Config. (Sara)
- Sodium:
. Added the XChaCha20 stream cipher functions. (P.I.E. Security Team)

View File

@ -120,6 +120,14 @@ PHP 8.1 UPGRADE NOTES
types. You can restore the previous behavior by enabling the
PDO::ATTR_STRINGIFY_FETCHES option.
- PSpell:
. The PSpell functions now accept and return, respectively, PSpell\Dictionary objects
instead of "pspell" resources. Return value checks using is_resource()
should be replaced with checks for `false`.
. The PSpell functions now accept and return, respectively, PSpell\Config objects
instead of "pspell config" resources. Return value checks using is_resource()
should be replaced with checks for `false`.
- Standard:
. version_compare() no longer accepts undocumented operator abbreviations.
. htmlspecialchars(), htmlentities(), htmlspecialchars_decode(),

View File

@ -88,7 +88,7 @@ static zend_object *php_pspell_object_to_zend_object(php_pspell_object *obj) {
static zend_function *php_pspell_object_get_constructor(zend_object *object)
{
zend_throw_error(NULL, "You cannot initialize a PSpell object except through helper functions");
zend_throw_error(NULL, "You cannot initialize a PSpell\\Dictionary object except through helper functions");
return NULL;
}
@ -126,7 +126,7 @@ static zend_object *php_pspell_config_object_to_zend_object(php_pspell_config_ob
static zend_function *php_pspell_config_object_get_constructor(zend_object *object)
{
zend_throw_error(NULL, "You cannot initialize a PSpellConfig object except through helper functions");
zend_throw_error(NULL, "You cannot initialize a PSpell\\Config object except through helper functions");
return NULL;
}
@ -150,7 +150,7 @@ static void php_pspell_config_object_free(zend_object *zobj) {
/* {{{ PHP_MINIT_FUNCTION */
static PHP_MINIT_FUNCTION(pspell)
{
php_pspell_ce = register_class_PSpell();
php_pspell_ce = register_class_PSpell_Dictionary();
php_pspell_ce->create_object = php_pspell_object_create;
php_pspell_ce->serialize = zend_class_serialize_deny;
php_pspell_ce->unserialize = zend_class_unserialize_deny;
@ -161,7 +161,7 @@ static PHP_MINIT_FUNCTION(pspell)
php_pspell_handlers.get_constructor = php_pspell_object_get_constructor;
php_pspell_handlers.offset = XtOffsetOf(php_pspell_object, std);
php_pspell_config_ce = register_class_PSpellConfig();
php_pspell_config_ce = register_class_PSpell_Config();
php_pspell_config_ce->create_object = php_pspell_config_object_create;
php_pspell_config_ce->serialize = zend_class_serialize_deny;
php_pspell_config_ce->unserialize = zend_class_unserialize_deny;

View File

@ -2,12 +2,17 @@
/** @generate-class-entries */
/** @strict-properties */
final class PSpell {}
/** @strict-properties */
final class PSpellConfig {}
namespace PSpell {
/** @strict-properties */
final class Dictionary {}
function pspell_new(string $language, string $spelling = "", string $jargon = "", string $encoding = "", int $mode = 0): PSpell|false {}
/** @strict-properties */
final class Config {}
}
namespace {
function pspell_new(string $language, string $spelling = "", string $jargon = "", string $encoding = "", int $mode = 0): PSpell\Dictionary|false {}
function pspell_new_personal(
string $filename,
@ -16,24 +21,26 @@ function pspell_new_personal(
string $jargon = "",
string $encoding = "",
int $mode = 0
): PSpell|false {}
): PSpell\Dictionary|false {}
function pspell_new_config(PSpellConfig $config): PSpell|false {}
function pspell_new_config(PSpell\Config $config): PSpell\Dictionary|false {}
function pspell_check(PSpell $dictionary, string $word): bool {}
function pspell_suggest(PSpell $dictionary, string $word): array|false {}
function pspell_store_replacement(PSpell $dictionary, string $misspelled, string $correct): bool {}
function pspell_add_to_personal(PSpell $dictionary, string $word): bool {}
function pspell_add_to_session(PSpell $dictionary, string $word): bool {}
function pspell_clear_session(PSpell $dictionary): bool {}
function pspell_save_wordlist(PSpell $dictionary): bool {}
function pspell_check(PSpell\Dictionary $dictionary, string $word): bool {}
function pspell_suggest(PSpell\Dictionary $dictionary, string $word): array|false {}
function pspell_store_replacement(PSpell\Dictionary $dictionary, string $misspelled, string $correct): bool {}
function pspell_add_to_personal(PSpell\Dictionary $dictionary, string $word): bool {}
function pspell_add_to_session(PSpell\Dictionary $dictionary, string $word): bool {}
function pspell_clear_session(PSpell\Dictionary $dictionary): bool {}
function pspell_save_wordlist(PSpell\Dictionary $dictionary): bool {}
function pspell_config_create(string $language, string $spelling = "", string $jargon = "", string $encoding = ""): PSpellConfig {}
function pspell_config_runtogether(PSpellConfig $config, bool $allow): bool {}
function pspell_config_mode(PSpellConfig $config, int $mode): bool {}
function pspell_config_ignore(PSpellConfig $config, int $min_length): bool {}
function pspell_config_personal(PSpellConfig $config, string $filename): bool {}
function pspell_config_dict_dir(PSpellConfig $config, string $directory): bool {}
function pspell_config_data_dir(PSpellConfig $config, string $directory): bool {}
function pspell_config_repl(PSpellConfig $config, string $filename): bool {}
function pspell_config_save_repl(PSpellConfig $config, bool $save): bool {}
function pspell_config_create(string $language, string $spelling = "", string $jargon = "", string $encoding = ""): PSpell\Config {}
function pspell_config_runtogether(PSpell\Config $config, bool $allow): bool {}
function pspell_config_mode(PSpell\Config $config, int $mode): bool {}
function pspell_config_ignore(PSpell\Config $config, int $min_length): bool {}
function pspell_config_personal(PSpell\Config $config, string $filename): bool {}
function pspell_config_dict_dir(PSpell\Config $config, string $directory): bool {}
function pspell_config_data_dir(PSpell\Config $config, string $directory): bool {}
function pspell_config_repl(PSpell\Config $config, string $filename): bool {}
function pspell_config_save_repl(PSpell\Config $config, bool $save): bool {}
}

View File

@ -1,7 +1,7 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: d7a2f6b4aa719778166e5a255432f03100184a42 */
* Stub hash: aedd25078f730be3892804dbe0c722fec2fbcf7e */
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new, 0, 1, PSpell, MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new, 0, 1, PSpell\\Dictionary, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, language, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, spelling, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, jargon, IS_STRING, 0, "\"\"")
@ -9,7 +9,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new, 0, 1, PSpell, MA
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new_personal, 0, 2, PSpell, MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new_personal, 0, 2, PSpell\\Dictionary, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, language, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, spelling, IS_STRING, 0, "\"\"")
@ -18,22 +18,22 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new_personal, 0, 2, P
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new_config, 0, 1, PSpell, MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new_config, 0, 1, PSpell\\Dictionary, MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_check, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell, 0)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell\\Dictionary, 0)
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pspell_suggest, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell, 0)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell\\Dictionary, 0)
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_store_replacement, 0, 3, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell, 0)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell\\Dictionary, 0)
ZEND_ARG_TYPE_INFO(0, misspelled, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, correct, IS_STRING, 0)
ZEND_END_ARG_INFO()
@ -43,12 +43,12 @@ ZEND_END_ARG_INFO()
#define arginfo_pspell_add_to_session arginfo_pspell_check
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_clear_session, 0, 1, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell, 0)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell\\Dictionary, 0)
ZEND_END_ARG_INFO()
#define arginfo_pspell_save_wordlist arginfo_pspell_clear_session
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_pspell_config_create, 0, 1, PSpellConfig, 0)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_pspell_config_create, 0, 1, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, language, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, spelling, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, jargon, IS_STRING, 0, "\"\"")
@ -56,27 +56,27 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_pspell_config_create, 0, 1, PSpel
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_runtogether, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, allow, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_mode, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_ignore, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, min_length, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_personal, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_dict_dir, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, directory, IS_STRING, 0)
ZEND_END_ARG_INFO()
@ -85,7 +85,7 @@ ZEND_END_ARG_INFO()
#define arginfo_pspell_config_repl arginfo_pspell_config_personal
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_save_repl, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, save, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
@ -135,31 +135,31 @@ static const zend_function_entry ext_functions[] = {
};
static const zend_function_entry class_PSpell_methods[] = {
static const zend_function_entry class_PSpell_Dictionary_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_PSpellConfig_methods[] = {
static const zend_function_entry class_PSpell_Config_methods[] = {
ZEND_FE_END
};
static zend_class_entry *register_class_PSpell(void)
static zend_class_entry *register_class_PSpell_Dictionary(void)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "PSpell", class_PSpell_methods);
INIT_NS_CLASS_ENTRY(ce, "PSpell", "Dictionary", class_PSpell_Dictionary_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES;
return class_entry;
}
static zend_class_entry *register_class_PSpellConfig(void)
static zend_class_entry *register_class_PSpell_Config(void)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "PSpellConfig", class_PSpellConfig_methods);
INIT_NS_CLASS_ENTRY(ce, "PSpell", "Config", class_PSpell_Config_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES;

View File

@ -34,7 +34,7 @@ var_dump(pspell_config_ignore($cfg, PHP_INT_MAX));
bool(false)
Warning: pspell_new_config(): PSPELL couldn't open the dictionary. reason: The encoding "b0rked" is not known. This could also mean that the file "%sb0rked.%s" could not be opened for reading or does not exist. in %s003.php on line 9
pspell_check(): Argument #1 ($dictionary) must be of type PSpell, bool given
pspell_check(): Argument #1 ($dictionary) must be of type PSpell\Dictionary, bool given
---
bool(true)
bool(true)