Merge pull request #52894 from nextcloud/chore/move-impl-util

chore: move implementation to non-deprecated OCP\Util from OC_Helper
pull/52893/head
Côme Chilliet 2025-05-16 12:28:42 +07:00 committed by GitHub
commit 12fdcd0826
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 53 deletions

@ -246,49 +246,30 @@ class OC_Helper {
/**
* Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
* Based on https://www.php.net/manual/en/function.array-change-key-case.php#107715
*
* @param array $input The array to work on
* @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
* @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
* @return array
*
* Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
* based on https://www.php.net/manual/en/function.array-change-key-case.php#107715
*
* @deprecated 4.5.0 use \OCP\Util::mb_array_change_key_case instead
*/
public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
$case = ($case != MB_CASE_UPPER) ? MB_CASE_LOWER : MB_CASE_UPPER;
$ret = [];
foreach ($input as $k => $v) {
$ret[mb_convert_case($k, $case, $encoding)] = $v;
}
return $ret;
return \OCP\Util::mb_array_change_key_case($input, $case, $encoding);
}
/**
* performs a search in a nested array
* Performs a search in a nested array.
* Taken from https://www.php.net/manual/en/function.array-search.php#97645
*
* @param array $haystack the array to be searched
* @param string $needle the search string
* @param mixed $index optional, only search this key name
* @return mixed the key of the matching field, otherwise false
*
* performs a search in a nested array
*
* taken from https://www.php.net/manual/en/function.array-search.php#97645
* @deprecated 4.5.0 - use \OCP\Util::recursiveArraySearch
*/
public static function recursiveArraySearch($haystack, $needle, $index = null) {
$aIt = new RecursiveArrayIterator($haystack);
$it = new RecursiveIteratorIterator($aIt);
while ($it->valid()) {
if (((isset($index) and ($it->key() == $index)) or !isset($index)) and ($it->current() == $needle)) {
return $aIt->key();
}
$it->next();
}
return false;
return \OCP\Util::recursiveArraySearch($haystack, $needle, $index);
}
/**
@ -297,12 +278,10 @@ class OC_Helper {
* @param string $dir the current folder where the user currently operates
* @param int|float $freeSpace the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
* @return int|float number of bytes representing
* @deprecated 5.0.0 - use \OCP\Util::maxUploadFilesize
*/
public static function maxUploadFilesize($dir, $freeSpace = null) {
if (is_null($freeSpace) || $freeSpace < 0) {
$freeSpace = self::freeSpace($dir);
}
return min($freeSpace, self::uploadLimit());
return \OCP\Util::maxUploadFilesize($dir, $freeSpace);
}
/**
@ -310,33 +289,20 @@ class OC_Helper {
*
* @param string $dir the current folder where the user currently operates
* @return int|float number of bytes representing
* @deprecated 7.0.0 - use \OCP\Util::freeSpace
*/
public static function freeSpace($dir) {
$freeSpace = \OC\Files\Filesystem::free_space($dir);
if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) {
$freeSpace = max($freeSpace, 0);
return $freeSpace;
} else {
return (INF > 0)? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
}
return \OCP\Util::freeSpace($dir);
}
/**
* Calculate PHP upload limit
*
* @return int|float PHP upload file size limit
* @deprecated 7.0.0 - use \OCP\Util::uploadLimit
*/
public static function uploadLimit() {
$ini = \OC::$server->get(IniGetWrapper::class);
$upload_max_filesize = Util::computerFileSize($ini->get('upload_max_filesize')) ?: 0;
$post_max_size = Util::computerFileSize($ini->get('post_max_size')) ?: 0;
if ($upload_max_filesize === 0 && $post_max_size === 0) {
return INF;
} elseif ($upload_max_filesize === 0 || $post_max_size === 0) {
return max($upload_max_filesize, $post_max_size); //only the non 0 value counts
} else {
return min($upload_max_filesize, $post_max_size);
}
return \OCP\Util::uploadLimit();
}
/**

@ -491,7 +491,12 @@ class Util {
* @since 4.5.0
*/
public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
return \OC_Helper::mb_array_change_key_case($input, $case, $encoding);
$case = ($case != MB_CASE_UPPER) ? MB_CASE_LOWER : MB_CASE_UPPER;
$ret = [];
foreach ($input as $k => $v) {
$ret[mb_convert_case($k, $case, $encoding)] = $v;
}
return $ret;
}
/**
@ -505,7 +510,18 @@ class Util {
* @deprecated 15.0.0
*/
public static function recursiveArraySearch($haystack, $needle, $index = null) {
return \OC_Helper::recursiveArraySearch($haystack, $needle, $index);
$aIt = new \RecursiveArrayIterator($haystack);
$it = new \RecursiveIteratorIterator($aIt);
while ($it->valid()) {
if (((isset($index) and ($it->key() == $index)) or !isset($index)) and ($it->current() == $needle)) {
return $aIt->key();
}
$it->next();
}
return false;
}
/**
@ -517,7 +533,10 @@ class Util {
* @since 5.0.0
*/
public static function maxUploadFilesize(string $dir, int|float|null $free = null): int|float {
return \OC_Helper::maxUploadFilesize($dir, $free);
if (is_null($free) || $free < 0) {
$free = self::freeSpace($dir);
}
return min($free, self::uploadLimit());
}
/**
@ -527,7 +546,13 @@ class Util {
* @since 7.0.0
*/
public static function freeSpace(string $dir): int|float {
return \OC_Helper::freeSpace($dir);
$freeSpace = \OC\Files\Filesystem::free_space($dir);
if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) {
$freeSpace = max($freeSpace, 0);
return $freeSpace;
} else {
return (INF > 0)? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
}
}
/**
@ -537,7 +562,16 @@ class Util {
* @since 7.0.0
*/
public static function uploadLimit(): int|float {
return \OC_Helper::uploadLimit();
$ini = Server::get(IniGetWrapper::class);
$upload_max_filesize = self::computerFileSize($ini->get('upload_max_filesize')) ?: 0;
$post_max_size = self::computerFileSize($ini->get('post_max_size')) ?: 0;
if ($upload_max_filesize === 0 && $post_max_size === 0) {
return INF;
} elseif ($upload_max_filesize === 0 || $post_max_size === 0) {
return max($upload_max_filesize, $post_max_size); //only the non 0 value counts
} else {
return min($upload_max_filesize, $post_max_size);
}
}
/**