Skip to content

Commit a1535f1

Browse files
committed
allow EnchantDict::__construct to use a PWL
1 parent 49e045b commit a1535f1

File tree

5 files changed

+48
-11
lines changed

5 files changed

+48
-11
lines changed

ext/enchant/enchant.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -512,30 +512,37 @@ PHP_FUNCTION(enchant_broker_request_dict)
512512
}
513513
/* }}} */
514514

515-
/* {{{ proto resource EnchantDict::__construct(resource broker, string tag)
516-
create a new dictionary using tag, the non-empty language tag you wish to request
517-
a dictionary for ("en_US", "de_DE", ...) */
515+
/* {{{ proto resource EnchantDict::__construct(resource broker, string tag [, string pwl])
516+
create a new dictionary using tag or pwl */
518517
PHP_METHOD(EnchantDict, __construct)
519518
{
520519
zval *broker;
521520
enchant_broker *pbroker;
522521
enchant_dict *dict;
523522
EnchantDict *pdict;
524-
char *tag;
525-
size_t taglen;
523+
char *tag, *pwl = NULL;
524+
size_t taglen, pwllen = 0;
526525

527-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &broker, enchant_broker_ce, &tag, &taglen) == FAILURE) {
526+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os|s", &broker, enchant_broker_ce, &tag, &taglen, &pwl, &pwllen) == FAILURE) {
528527
RETURN_THROWS();
529528
}
530529

531530
PHP_ENCHANT_GET_BROKER;
532531

533-
if (taglen == 0) {
534-
zend_value_error("Tag cannot be empty");
535-
RETURN_THROWS();
532+
if (pwllen) {
533+
if (php_check_open_basedir_ex(pwl, 0)) {
534+
zend_value_error("Open_basedir restriction in effect");
535+
RETURN_THROWS();
536+
}
537+
pdict = enchant_broker_request_pwl_dict(pbroker->pbroker, pwl);
538+
} else {
539+
if (taglen == 0) {
540+
zend_value_error("Tag cannot be empty");
541+
RETURN_THROWS();
542+
}
543+
pdict = enchant_broker_request_dict(pbroker->pbroker, (const char *)tag);
536544
}
537545

538-
pdict = enchant_broker_request_dict(pbroker->pbroker, (const char *)tag);
539546
if (pdict) {
540547
pbroker->nb_dict++;
541548

ext/enchant/enchant.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function describe(): ?array {}
3131

3232
final class EnchantDict
3333
{
34-
public function __construct(EnchantBroker $broker, string $tag) {}
34+
public function __construct(EnchantBroker $broker, string $tag, ?string $tag = null) {}
3535

3636
/** @alias enchant_dict_quick_check */
3737
public function checkAndSuggest(string $word, &$suggestions = null): bool {}

ext/enchant/enchant_arginfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ ZEND_END_ARG_INFO()
127127
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_EnchantDict___construct, 0, 0, 2)
128128
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
129129
ZEND_ARG_TYPE_INFO(0, tag, IS_STRING, 0)
130+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, tag, IS_STRING, 1, "null")
130131
ZEND_END_ARG_INFO()
131132

132133
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_EnchantDict_checkAndSuggest, 0, 1, _IS_BOOL, 0)

ext/enchant/tests/construct.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
constructor raise exception()
3+
--SKIPIF--
4+
<?php
5+
if(!extension_loaded('enchant')) die('skip, enchant not loader');
6+
if (!is_object(enchant_broker_init())) {die("skip, resource dont load\n");}
7+
?>
8+
--FILE--
9+
<?php
10+
try {
11+
new EnchantDict(new EnchantBroker, '');
12+
} catch (ValueError $e) {
13+
echo $e->getMessage()."\n";
14+
}
15+
?>
16+
OK
17+
--EXPECTF--
18+
Tag cannot be empty
19+
OK

ext/enchant/tests/object.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ var_dump($dict->isAdded($w));
2929

3030
echo "+ Suggest\n";
3131
var_dump(is_array($dict->suggest("soong")));
32+
33+
echo "+ PWL\n";
34+
var_dump($dict = new EnchantDict($broker, '', __DIR__ . '/enchant_broker_request_pwl_dict.pwl'));
35+
var_dump($dict->check('php'));
36+
var_dump($dict->check('node'));
3237
?>
3338
OK
3439
--EXPECTF--
@@ -50,4 +55,9 @@ bool(true)
5055
bool(true)
5156
+ Suggest
5257
bool(true)
58+
+ PWL
59+
object(EnchantDict)#%d (0) {
60+
}
61+
bool(true)
62+
bool(false)
5363
OK

0 commit comments

Comments
 (0)