From 1e876466f8fc9a78c72204c283f34abdbc11358a Mon Sep 17 00:00:00 2001 From: Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr> Date: Tue, 6 Dec 2022 14:51:50 +0100 Subject: [PATCH] Test d'existence de ldap_sort pour informer que la fonction n'existe plus depuis PHP 8.0 --- src/UnicaenLdap/Service/AbstractService.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/UnicaenLdap/Service/AbstractService.php b/src/UnicaenLdap/Service/AbstractService.php index 8ff789f..a741996 100644 --- a/src/UnicaenLdap/Service/AbstractService.php +++ b/src/UnicaenLdap/Service/AbstractService.php @@ -161,8 +161,11 @@ abstract class AbstractService implements if ($this->count > 0) { if ($orderBy !== null && is_string($orderBy)) { + if (! function_exists($ldapSort = 'ldap_sort')) { + throw new \BadFunctionCallException("Impossible de trier, la fonction 'ldap_sort' n'existe plus depuis PHP 8.0"); + } ErrorHandler::start(E_WARNING); - $isSorted = ldap_sort($resource, $search, $orderBy); + $isSorted = $ldapSort($resource, $search, $orderBy); ErrorHandler::stop(); if ($isSorted === false) { throw new Exception($this, 'sorting: ' . $orderBy); @@ -235,8 +238,11 @@ abstract class AbstractService implements ErrorHandler::stop(); if ($this->count > 0) { if ($orderBy !== null && is_string($orderBy)) { + if (! function_exists($ldapSort = 'ldap_sort')) { + throw new \BadFunctionCallException("Impossible de trier, la fonction 'ldap_sort' n'existe plus depuis PHP 8.0"); + } ErrorHandler::start(E_WARNING); - $isSorted = ldap_sort($resource, $search, $orderBy); + $isSorted = $ldapSort($resource, $search, $orderBy); ErrorHandler::stop(); if ($isSorted === false) { throw new Exception($this, 'sorting: ' . $orderBy); -- GitLab