mirror of
https://github.com/roundcube/roundcubemail.git
synced 2025-12-27 23:45:58 +00:00
Use symfony/polyfill-php85 for array_first() and array_last()
This commit is contained in:
parent
918e22be42
commit
1e55383302
@ -16,7 +16,8 @@
|
||||
"pear/net_smtp": "~1.12.0",
|
||||
"pear/pear-core-minimal": "~1.10.15",
|
||||
"roundcube/plugin-installer": "~0.3.5",
|
||||
"roundcube/rtf-html-php": "^2.1"
|
||||
"roundcube/rtf-html-php": "^2.1",
|
||||
"symfony/polyfill-php85": "^1.33.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ergebnis/composer-normalize": "^2.13",
|
||||
|
||||
@ -311,7 +311,7 @@ class vcard_attachments extends rcube_plugin
|
||||
// Get first writeable addressbook if the configured doesn't exist
|
||||
// This can happen when user deleted the addressbook (e.g. Kolab folder)
|
||||
if (!is_object($CONTACTS)) {
|
||||
$source = reset($rcmail->get_address_sources(true));
|
||||
$source = array_first($rcmail->get_address_sources(true));
|
||||
$CONTACTS = $rcmail->get_address_book($source['id'], true);
|
||||
}
|
||||
|
||||
|
||||
@ -648,7 +648,7 @@ class rcmail_action_contacts_index extends rcmail_action
|
||||
foreach ($result as $row) {
|
||||
$emails = rcube_addressbook::get_col_values('email', $row, true);
|
||||
$row['CID'] = $row['ID'];
|
||||
$row['email'] = reset($emails);
|
||||
$row['email'] = array_first($emails);
|
||||
$source_id = $rcmail->output->get_env('source');
|
||||
$a_row_cols = [];
|
||||
$type = !empty($row['_type']) ? $row['_type'] : 'person';
|
||||
|
||||
@ -354,7 +354,7 @@ class rcmail extends rcube
|
||||
// This can happen when user deleted the addressbook (e.g. Kolab folder)
|
||||
if ($fallback && !$contacts && (!$id || $default)) {
|
||||
$source = $this->get_address_sources($writeable, !$default);
|
||||
$source = reset($source);
|
||||
$source = array_first($source);
|
||||
|
||||
if (!empty($source)) {
|
||||
// Note: No fallback here to prevent from an infinite loop
|
||||
|
||||
@ -525,7 +525,7 @@ class rcmail_install
|
||||
foreach ($lines as $line) {
|
||||
if (preg_match('/^\s*create table ([\S]+)/i', $line, $m)) {
|
||||
$table_name = explode('.', $m[1]);
|
||||
$table_name = end($table_name);
|
||||
$table_name = array_last($table_name);
|
||||
$table_name = preg_replace('/[`"\[\]]/', '', $table_name);
|
||||
} elseif (preg_match('/insert into/i', $line) && preg_match('/\'roundcube-version\',\s*\'([0-9]+)\'/', $line, $m)) {
|
||||
$version = $m[1];
|
||||
|
||||
@ -340,8 +340,7 @@ class rcmail_output_html extends rcmail_output
|
||||
$meta = $this->get_skin_info($skin_name);
|
||||
|
||||
$meta['path'] = $skin_path;
|
||||
$path_elements = explode('/', $skin_path);
|
||||
$skin_id = end($path_elements);
|
||||
$skin_id = array_last(explode('/', $skin_path));
|
||||
|
||||
if (empty($meta['name'])) {
|
||||
$meta['name'] = $skin_id;
|
||||
|
||||
@ -308,7 +308,7 @@ class rcmail_utils
|
||||
if (is_string($hosts)) {
|
||||
$args['host'] = $hosts;
|
||||
} elseif (is_array($hosts) && count($hosts) == 1) {
|
||||
$args['host'] = reset($hosts);
|
||||
$args['host'] = array_first($hosts);
|
||||
} else {
|
||||
rcube::raise_error('Specify a host name', false, true);
|
||||
}
|
||||
|
||||
@ -283,29 +283,6 @@ function array_keys_recursive($array)
|
||||
return $keys;
|
||||
}
|
||||
|
||||
// Function added in PHP 8.5
|
||||
if (!function_exists('array_first')) {
|
||||
/**
|
||||
* Get first element from an array
|
||||
*
|
||||
* @param array $array Input array
|
||||
*
|
||||
* @return mixed First element if found, Null otherwise
|
||||
*/
|
||||
function array_first($array)
|
||||
{
|
||||
// @phpstan-ignore-next-line
|
||||
if (is_array($array) && !empty($array)) {
|
||||
reset($array);
|
||||
foreach ($array as $element) {
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all non-ascii and non-word chars except ., -, _
|
||||
*
|
||||
|
||||
@ -1035,7 +1035,7 @@ class rcube_imap extends rcube_storage
|
||||
$parents = array_slice($parents, 0, $depth);
|
||||
|
||||
if (!empty($parents)) {
|
||||
$headers[$uid]->parent_uid = end($parents);
|
||||
$headers[$uid]->parent_uid = array_last($parents);
|
||||
if (empty($header->flags['SEEN'])) {
|
||||
$headers[$parents[0]]->unread_children++;
|
||||
}
|
||||
|
||||
@ -1138,7 +1138,7 @@ class rcube_imap_cache
|
||||
*
|
||||
* @param array $sql_arr Message row data
|
||||
*
|
||||
* @return rcube_message_header Message object
|
||||
* @return ?rcube_message_header Message object
|
||||
*/
|
||||
private function build_message($sql_arr)
|
||||
{
|
||||
|
||||
@ -253,8 +253,8 @@ class rcube_result_multifolder
|
||||
public function get_element($idx)
|
||||
{
|
||||
switch ($idx) {
|
||||
case 'FIRST': return $this->index[0];
|
||||
case 'LAST': return end($this->index);
|
||||
case 'FIRST': return $this->index[0] ?? null;
|
||||
case 'LAST': return array_last($this->index);
|
||||
default: return $this->index[$idx] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user