Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
refactor(array/function): move setDefault to \Rid class
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jul 22, 2019
1 parent 854722a commit b49d529
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions framework/Rid.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ public static function createObject($config)
return new $class($config);
}

public static function setDefault(&$array, $defaults)
{
if (!is_array($array)) $array = [$array];
foreach ($defaults as $key => $default) {
if (!array_key_exists($key, $array)) {
$array[$key] = $default;
}
}
}
}
8 changes: 4 additions & 4 deletions framework/View/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function setDefault(&$array, $defaults)

public function format_bytes($var)
{
self::setDefault($var, ['precision' => 2, 'separator' => ' ']);
\Rid::setDefault($var, ['precision' => 2, 'separator' => ' ']);
$bytes = array_shift($var);

$units = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
Expand All @@ -56,19 +56,19 @@ public function format_bytes($var)

public function format_bytes_compact($var)
{
self::setDefault($var, ['precision' => 2, 'separator' => '<br />']);
\Rid::setDefault($var, ['precision' => 2, 'separator' => '<br />']);
return $this->format_bytes($var);
}

public function format_bytes_loose($var)
{
self::setDefault($var, ['precision' => 2, 'separator' => '&nbsp;']);
\Rid::setDefault($var, ['precision' => 2, 'separator' => '&nbsp;']);
return $this->format_bytes($var);
}

public function format_ubbcode($var)
{
self::setDefault($var, ['escapeHtml' => true]);
\Rid::setDefault($var, ['escapeHtml' => true]);
$string = array_shift($var);

$code = new Decoda($string, $var,'Cache:post:' . md5($string));
Expand Down

0 comments on commit b49d529

Please sign in to comment.