-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.php
More file actions
75 lines (68 loc) · 1.96 KB
/
sample.php
File metadata and controls
75 lines (68 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* バイトを単位に変換する
*
* 出典:https://qiita.com/git6_com/items/ecaafb1afb42fc207814
*/
function prettyByte2Str($bytes)
{
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 1) . ' GB';
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 1) . ' MB';
} elseif ($bytes >= 1024) {
$bytes = number_format($bytes / 1024, 1, '.') . ' KB';
} elseif ($bytes > 1) {
$bytes = $bytes . ' bytes';
} elseif ($bytes == 1) {
$bytes = $bytes . ' byte';
} else {
$bytes = '0 bytes';
}
return $bytes;
}
/**
* 文字列のtrueとfalseを論理型に変換
*
* クエリーパラメーターで送られてきた文字列のtrueとfalseを
* 論理型に変換したい時に使う
*
* @param string 変換したい文字列
* @return boolean|null
*/
function convertBoolean(string $value)
{
if ($value === 'true') {
return true;
} elseif ($value === 'true') {
return false;
}
return null;
}
/**
* スネークケースをローワーキャメルケースに変換する
*
* @param string 変換したい文字列
* @return string
*/
function convertSnakeCaseToLowerCamelCase($snake_case)
{
$convert_list = str_split($snake_case);
// 大文字変換フラグ
$uppercase_flg = false;
// ローワーキャメルケースに変換
foreach ($convert_list as $key => $value){
if($uppercase_flg === true){
$convert_list[$key] = strtoupper($convert_list[$key]);
// 次の文字列は、変換の必要がないため
$uppercase_flg = false;
}
if($value === '_'){
// 「-」の次の文字列は大文字にする必要があるので、フラグをtrueにする
$uppercase_flg = true;
// 「-」は不要なので削除
unset($convert_list[$key]);
}
};
return implode($convert_list);
}