Skip to content

Commit

Permalink
Reverting stdlib changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phpmathan committed Jul 18, 2020
1 parent cc44a03 commit c593da6
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 123 deletions.
84 changes: 0 additions & 84 deletions src/stdlib/src/Helper/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1392,88 +1392,4 @@ public static function shuffle($array, $seed = null)

return $array;
}

/**
* Shorten an multidimensional array into a single dimensional array concatenating all keys with separator.
*
* [
* 'country' => [
* 0 => [
* 'name' => 'Bangladesh',
* 'capital' => 'Dhaka'
* ]
* ]
* ]
*
* to [
* 'country.0.name' => 'Bangladesh',
* 'country.0.capital' => 'Dhaka'
* ]
*
* @param array $input
* @param string $separator
* @param string|int $path
*
* @return array
*/
public static function short(array $input, string $separator = '.', $path = null): array
{
$data = [];

if ($path !== null) {
$path .= $separator;
}

foreach ($input as $key => &$value) {
if ((array) $value !== $value) {
$data[$path.$key] = $value;
} else {
$data = array_merge($data, static::short($value, $separator, $path.$key));
}
}

return $data;
}

/**
* Unshorten a single dimensional array into multidimensional array.
*
* [
* 'country.0.name' => 'Bangladesh',
* 'country.0.capital' => 'Dhaka'
* ]
*
* to [
* 'country' => [
* 0 => [
* 'name' => 'Bangladesh',
* 'capital' => 'Dhaka'
* ]
* ]
* ]
*
* @param array $input
* @param string $separator
*
* @return array
*/
public static function unshort(array $input, string $separator = '.'): array
{
$result = [];

foreach ($input as $key => $value) {
if (strpos($key, $separator) !== false) {
$str = explode($separator, $key, 2);
$result[$str[0]][$str[1]] = $value;

if (strpos($str[1], $separator)) {
$result[$str[0]] = static::unshort($result[$str[0]], $separator);
}
} else {
$result[$key] = is_array($value) ? static::unshort($value, $separator) : $value;
}
}

return $result;
}
}
38 changes: 0 additions & 38 deletions src/stdlib/src/Helper/ObjectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use InvalidArgumentException;
use ReflectionProperty;
use stdClass;
use Throwable;
use function is_numeric;
use function json_encode;
Expand Down Expand Up @@ -175,41 +174,4 @@ public static function getDefaultValue(string $type)

return $value;
}

/**
* Converts an array into standard object.
*
* @param array
*
* @return stdClass
*/
public static function toObject(array $array): stdClass
{
$object = new stdClass;

if (!$array) {
return $object;
}

foreach ($array as $name => $value) {
if ($name == '') {
continue;
}

$isNumericArray = false;

if ((array) $value === $value) {
foreach ($value as $k => $v) {
if (is_numeric($k)) {
$isNumericArray = true;
break;
}
}
}

$object->$name = $isNumericArray ? $value : static::toObject($value);
}

return $object;
}
}
2 changes: 1 addition & 1 deletion src/stdlib/src/Helper/PhpHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PhpHelper
*
* @return mixed
*/
public static function call($cb, &...$args)
public static function call($cb, ...$args)
{
if (is_string($cb)) {
// className::method
Expand Down

0 comments on commit c593da6

Please sign in to comment.