Skip to content

Commit fdd82fc

Browse files
committed
Add LDAP\Connection::delete, same as ldap_delete_ext
Signed-off-by: Côme Chilliet <mcmic@php.net>
1 parent 2d7c267 commit fdd82fc

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

‎ext/ldap/ldap.c‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,8 +2672,15 @@ static void php_ldap_do_delete(INTERNAL_FUNCTION_PARAMETERS, bool ext)
26722672
int rc, msgid;
26732673
size_t dn_len;
26742674

2675-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op|h!", &link, ldap_link_ce, &dn, &dn_len, &server_controls_ht) != SUCCESS) {
2676-
RETURN_THROWS();
2675+
if (ZEND_IS_METHOD_CALL()) {
2676+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|h!", &dn, &dn_len, &server_controls_ht) != SUCCESS) {
2677+
RETURN_THROWS();
2678+
}
2679+
link = ZEND_THIS;
2680+
} else {
2681+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op|h!", &link, ldap_link_ce, &dn, &dn_len, &server_controls_ht) != SUCCESS) {
2682+
RETURN_THROWS();
2683+
}
26772684
}
26782685

26792686
ld = Z_LDAP_LINK_P(link);
@@ -2693,15 +2700,23 @@ static void php_ldap_do_delete(INTERNAL_FUNCTION_PARAMETERS, bool ext)
26932700
rc = ldap_delete_ext_s(ld->link, dn, lserverctrls, NULL);
26942701
}
26952702
if (rc != LDAP_SUCCESS) {
2696-
php_error_docref(NULL, E_WARNING, "Delete: %s", ldap_err2string(rc));
2697-
RETVAL_FALSE;
2703+
if (ZEND_IS_METHOD_CALL()) {
2704+
zend_throw_exception_ex(ldap_exception_ce, rc, "Delete: %s", ldap_err2string(rc));
2705+
} else {
2706+
php_error_docref(NULL, E_WARNING, "Delete: %s", ldap_err2string(rc));
2707+
RETVAL_FALSE;
2708+
}
26982709
goto cleanup;
26992710
} else if (ext) {
27002711
LDAPMessage *ldap_res;
27012712
rc = ldap_result(ld->link, msgid, 1 /* LDAP_MSG_ALL */, NULL, &ldap_res);
27022713
if (rc == -1) {
2703-
php_error_docref(NULL, E_WARNING, "Delete operation failed");
2704-
RETVAL_FALSE;
2714+
if (ZEND_IS_METHOD_CALL()) {
2715+
zend_throw_exception_ex(ldap_exception_ce, 0, "Delete operation failed");
2716+
} else {
2717+
php_error_docref(NULL, E_WARNING, "Delete operation failed");
2718+
RETVAL_FALSE;
2719+
}
27052720
goto cleanup;
27062721
}
27072722

@@ -2730,6 +2745,11 @@ PHP_FUNCTION(ldap_delete)
27302745
/* }}} */
27312746

27322747
/* {{{ Delete an entry from a directory */
2748+
PHP_METHOD(LDAP_Connection, delete)
2749+
{
2750+
php_ldap_do_delete(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
2751+
}
2752+
27332753
PHP_FUNCTION(ldap_delete_ext)
27342754
{
27352755
php_ldap_do_delete(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);

‎ext/ldap/ldap.stub.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ public function add(string $dn, array $entry, ?array $controls = null): Result;
851851
public function mod_add(string $dn, array $entry, ?array $controls = null): Result;
852852
public function mod_del(string $dn, array $entry, ?array $controls = null): Result;
853853
public function mod_replace(string $dn, array $entry, ?array $controls = null): Result;
854+
public function delete(string $dn, ?array $controls = null): Result;
854855
}
855856

856857
/**

‎ext/ldap/ldap_arginfo.h‎

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)