Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 10 additions & 98 deletions libraries/joomla/utilities/arrayhelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,7 @@ abstract class JArrayHelper
*/
public static function toInteger(&$array, $default = null)
{
if (is_array($array))
{
foreach ($array as $i => $v)
{
$array[$i] = (int) $v;
}
}
else
{
if ($default === null)
{
$array = array();
}
elseif (is_array($default))
{
self::toInteger($default, null);
$array = $default;
}
else
{
$array = array((int) $default);
}
}
$array = ArrayHelper::toInteger($array, $default);
}

/**
Expand Down Expand Up @@ -166,7 +144,7 @@ public static function fromObject($p_obj, $recurse = true, $regex = null)
}
else
{
return;
return null;
}
}

Expand Down Expand Up @@ -327,64 +305,15 @@ public static function isAssociative($array)
public static function pivot($source, $key = null)
{
$result = array();
$counter = array();

foreach ($source as $index => $value)
if (is_array($source))
{
// Determine the name of the pivot key, and its value.
if (is_array($value))
{
// If the key does not exist, ignore it.
if (!isset($value[$key]))
{
continue;
}

$resultKey = $value[$key];
$resultValue = &$source[$index];
}
elseif (is_object($value))
{
// If the key does not exist, ignore it.
if (!isset($value->$key))
{
continue;
}

$resultKey = $value->$key;
$resultValue = &$source[$index];
}
else
{
// Just a scalar value.
$resultKey = $value;
$resultValue = $index;
}

// The counter tracks how many times a key has been used.
if (empty($counter[$resultKey]))
{
// The first time around we just assign the value to the key.
$result[$resultKey] = $resultValue;
$counter[$resultKey] = 1;
}
elseif ($counter[$resultKey] == 1)
{
// If there is a second time, we convert the value into an array.
$result[$resultKey] = array(
$result[$resultKey],
$resultValue,
);
$counter[$resultKey]++;
}
else
{
// After the second time, no need to track any more. Just append to the existing array.
$result[$resultKey][] = $resultValue;
}
$result = ArrayHelper::pivot($source, $key);
}
else
{
JLog::add('This method is typehinted to be an array in \Joomla\Utilities\ArrayHelper::pivot.', JLog::WARNING, 'deprecated');
}

unset($counter);

return $result;
}
Expand Down Expand Up @@ -494,29 +423,12 @@ protected static function _sortObjects(&$a, &$b)
*
* @return array
*
* @see https://secure.php.net/manual/en/function.array-unique.php
* @see http://php.net/manual/en/function.array-unique.php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should stay to be https or do we have any reason to set it to http?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @since 11.2
* @deprecated 4.0 Use Joomla\Utilities\ArrayHelper::arrayUnique instead
*/
public static function arrayUnique($myArray)
{
if (!is_array($myArray))
{
return $myArray;
}

foreach ($myArray as &$myvalue)
{
$myvalue = serialize($myvalue);
}

$myArray = array_unique($myArray);

foreach ($myArray as &$myvalue)
{
$myvalue = unserialize($myvalue);
}

return $myArray;
return is_array($myArray) ? ArrayHelper::arrayUnique($myArray) : $myArray;
}
}