Skip to content

Commit 7ab4b8a

Browse files
0.6.1
* [*] some additions
1 parent 505698f commit 7ab4b8a

File tree

6 files changed

+45
-9
lines changed

6 files changed

+45
-9
lines changed

sources/Helpers/Arrays.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public static function jsonize($data)
271271
* @param $arr
272272
* @return array
273273
*/
274-
public static function flatten($arr)
274+
public static function flatten($arr): array
275275
{
276276
return \array_merge(...\array_values($arr));
277277
}
@@ -300,6 +300,25 @@ public static function order_by(array $data, ...$args): array
300300
\call_user_func_array('array_multisort', $args);
301301
return \array_pop($args);
302302
}
303+
304+
/**
305+
* @param $input_array
306+
* @param $required_key
307+
* @param $allowed_values
308+
* @param $default_value
309+
* @return mixed
310+
*/
311+
public static function filter_array_for_allowed($input_array, $required_key, $allowed_values, $default_value)
312+
{
313+
return
314+
\array_key_exists($required_key, $input_array)
315+
?
316+
(
317+
\in_array($input_array[ $required_key ], $allowed_values)
318+
? $input_array[ $required_key ]
319+
: $default_value
320+
) : $default_value;
321+
}
303322

304323

305324

sources/Helpers/DB.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function makeInsertQuery(string $table, &$dataset):string
2929

3030
$set = [];
3131

32-
$query = "INSERT INTO `{$table}` SET ";
32+
$query = "INSERT INTO {$table} SET ";
3333

3434
foreach ($dataset as $index => $value) {
3535
if (\strtoupper(trim($value)) === 'NOW()') {

sources/Helpers/Debug.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<?php
22

3-
43
namespace Arris\Helpers;
54

6-
75
class Debug
86
{
9-
107
/**
118
* Печать массива в том виде, в каком его понимает php
129
*

sources/Helpers/INI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class INI
99
{
1010
public static function get_ini_value($key)
1111
{
12-
return (int)Strings::return_bytes(ini_get($key));
12+
return Strings::return_bytes(ini_get($key));
1313
}
1414

1515
/**

sources/Helpers/Misc.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ public static function GUID()
4646
\random_int(0, 65535)
4747
);
4848
}
49+
50+
public static function UUID()
51+
{
52+
return self::GUID();
53+
}
54+
55+
/**
56+
*
57+
* @param int $size
58+
* @param int $decimals
59+
* @param string $decimal_separator
60+
* @param string $thousands_separator
61+
* @return string
62+
*/
63+
public static function size_format(int $size, int $decimals = 0, string $decimal_separator = '.', string $thousands_separator = ','): string {
64+
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
65+
$index = min(floor((strlen(strval($size)) - 1) / 3), count($units) - 1);
66+
$number = number_format($size / pow(1000, $index), $decimals, $decimal_separator, $thousands_separator);
67+
return sprintf('%s %s', $number, $units[$index]);
68+
}
4969

5070

5171

sources/Helpers/Strings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class Strings
1717
public static function return_bytes($val):int
1818
{
1919
$val = \trim($val);
20-
$last = \strtolower( $val[ \strlen($val)-1 ] );
20+
$suffix = \strtolower( $val[ \strlen($val)-1 ] );
2121
$val = (int)$val;
2222

23-
switch($last) {
23+
switch($suffix) {
2424
case 'g':
2525
$val = $val << 10;
2626
case 'm':
@@ -161,7 +161,7 @@ public static function vksprintf($str, $args)
161161
*/
162162
public static function pluralForm($number, $forms, string $glue = '|'):string
163163
{
164-
if (@empty($forms)) {
164+
if (empty($forms)) {
165165
return $number;
166166
}
167167

0 commit comments

Comments
 (0)