Skip to content

Commit fac1412

Browse files
update
1 parent 59639b2 commit fac1412

File tree

12 files changed

+162
-64
lines changed

12 files changed

+162
-64
lines changed

Capsule/TimeHelper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ static public function setPassedTimezone($timezone = null)
3535
static public function setPassedDate($date = null)
3636
{
3737
if(empty($date)){
38-
$date = date('M d Y', strtotime('this year January'));
38+
// $date = date('M d Y', strtotime('this year January'));
3939
$date = "Jan 01 1970";
4040
}
4141

4242
if (is_numeric($date)) {
4343
$date = date('M d Y', (int) $date);
4444
}
4545

46+
// if instance of Carbon
47+
// then convert to date time
48+
if($date instanceof \Illuminate\Support\Carbon){
49+
$date = $date->toDateTimeString();
50+
}
51+
4652
return strtotime($date);
4753
}
4854

NumberToWords.php

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class NumberToWords {
1414
/**
1515
* Allow cents text to be added
1616
*
17-
* @var boolean
17+
* @var bool|null
1818
*/
19-
static private $allowCents = false;
19+
static private $allowCents;
2020

2121
/**
2222
* Currency data
@@ -25,30 +25,59 @@ class NumberToWords {
2525
*/
2626
static private $currencyData;
2727

28+
/**
29+
* Allow Cents
30+
* @param bool|null $cents
31+
* - [optional] Default is false
32+
*
33+
* @return $this
34+
*/
35+
static public function cents($cents = null)
36+
{
37+
$self = clone new self();
38+
39+
self::$allowCents = $cents;
40+
41+
return $self;
42+
}
43+
44+
/**
45+
* Country <iso-3></iso-3> code
46+
*
47+
* @param string|null $code
48+
* - [optional] Currency code
49+
*
50+
* @return $this
51+
*/
52+
static public function iso($code = null)
53+
{
54+
$self = clone new self();
55+
56+
self::$currencyData = self::getCurrencyText($code);
57+
58+
return $self;
59+
}
60+
2861
/**
2962
* Convert a number to its text representation.
30-
* - Can be able to convert numbers unto quintillion
63+
* - Can be able to convert numbers upto <quintillion>
3164
*
3265
* @param string|int|float $number
3366
*
34-
* @param bool $cents
67+
* @param bool|null $cents
3568
* - [optional] Default is false
3669
*
37-
* @param string|null $code
38-
* - [optional] Currency code
39-
*
4070
* @return string
4171
*/
42-
static public function text($number, $code = null, $cents = false)
72+
static public function text($number, $cents = null)
4373
{
44-
self::$allowCents = $cents;
74+
if(is_null(self::$allowCents) && is_bool($cents)){
75+
self::$allowCents = $cents;
76+
}
4577

4678
// trim to convert to string
4779
$number = Str::trim($number);
4880

49-
// get currency code
50-
self::$currencyData = self::getCurrencyText($code);
51-
5281
// if cents is allowed
5382
if(self::$allowCents){
5483

@@ -98,9 +127,15 @@ static private function toCents($number)
98127
// allow if not empty
99128
$centsText = !empty($centsText) ? " {$centsText}" : '';
100129

130+
// reset allowCents
131+
self::$allowCents = null;
132+
101133
return ", {$centsCurrency}{$centsText}";
102134
}
103135
}
136+
137+
// reset allowCents
138+
self::$allowCents = null;
104139
}
105140

106141
/**
@@ -173,8 +208,6 @@ static private function convertChunkToText($number)
173208
}
174209

175210
return $result;
176-
177-
178211
}
179212

180213
/**

Str.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,28 @@ public static function convertArrayCase(array $data, string $key = 'lower', stri
156156
return $result;
157157
}
158158

159+
/**
160+
* Check if array has duplicate value
161+
*
162+
* @param array $data
163+
* @return bool
164+
*/
165+
static public function arrayDuplicate(?array $data = [])
166+
{
167+
return count($data) > count(array_unique($data));
168+
}
169+
170+
/**
171+
* Check if all values of array is same
172+
*
173+
* @param array $data
174+
* @return bool
175+
*/
176+
static public function arraySame(?array $data = [])
177+
{
178+
return count(array_unique($data)) === 1;
179+
}
180+
159181
/**
160182
* Merge the binding arrays into a single array.
161183
*

Tame.php

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,39 @@ static public function echoJson(int $response = 0, $message = null)
6060
echo json_encode(['response' => $response, 'message' => $message]);
6161
}
6262

63+
/**
64+
* Check IF URL Exists
65+
*
66+
* @param string $url
67+
* @return bool
68+
*/
69+
static public function urlExists($url)
70+
{
71+
$ch = curl_init($url);
72+
73+
// Set cURL options
74+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
75+
curl_setopt($ch, CURLOPT_HEADER, true);
76+
curl_setopt($ch, CURLOPT_NOBODY, true);
77+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects
78+
79+
// Execute cURL and get the HTTP status code
80+
$httpCode = curl_exec($ch);
81+
82+
// Close cURL handle
83+
curl_close($ch);
84+
85+
return $httpCode && preg_match('/\b200\b/', $httpCode);
86+
}
87+
6388
/**
6489
* Check IF Internet is Available
65-
*
90+
*
6691
* @return bool
6792
*/
6893
static public function isInternetAvailable()
6994
{
70-
// Use cURL to make a request
71-
$request = curl_init('https://www.google.com');
72-
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
73-
curl_setopt($request, CURLOPT_TIMEOUT, 5);
74-
curl_exec($request);
75-
76-
// Check the HTTP response code
77-
$httpCode = curl_getinfo($request, CURLINFO_HTTP_CODE);
78-
curl_close($request);
79-
80-
// HTTP code 200 means the request was successful
81-
return $httpCode === 200;
95+
return self::urlExists('https://www.google.com');
8296
}
8397

8498
/**
@@ -511,11 +525,7 @@ static public function calPercentageBetweenNumbers(float|int $total = 0, float|i
511525
*/
512526
static public function isArrayDuplicate(?array $data = [])
513527
{
514-
if(count($data) > count(array_unique($data))){
515-
return true;
516-
}
517-
518-
return false;
528+
return Str::arrayDuplicate($data);
519529
}
520530

521531
/**
@@ -527,11 +537,7 @@ static public function isArrayDuplicate(?array $data = [])
527537
*/
528538
static public function isArraySame(?array $data = [])
529539
{
530-
if(count($data) > count(array_unique($data))){
531-
return true;
532-
}
533-
534-
return false;
540+
return Str::arraySame($data);
535541
}
536542

537543
/**
@@ -547,34 +553,31 @@ static public function sortArray(?array $data = [], ?string $type = 'sort')
547553
{
548554
switch ($type) {
549555
case 'rsort':
550-
rsort($data); return $data; //sort arrays in descending order
556+
rsort($data); // sort arrays in descending order
551557
break;
552-
558+
553559
case 'asort':
554-
asort($data);
555-
return asort($data); //sort associative arrays in ascending order, according to the value
560+
asort($data); // sort associative arrays in ascending order, according to the value
556561
break;
557-
562+
558563
case 'ksort':
559-
ksort($data);
560-
return $data; //sort associative arrays in ascending order, according to the key
564+
ksort($data); // sort associative arrays in ascending order, according to the key
561565
break;
562-
566+
563567
case 'arsort':
564-
arsort($data);
565-
return $data; //sort associative arrays in descending order, according to the value
568+
arsort($data); // sort associative arrays in descending order, according to the value
566569
break;
567-
570+
568571
case 'krsort':
569-
krsort($data);
570-
return $data; //sort associative arrays in descending order, according to the value
572+
krsort($data); // sort associative arrays in descending order, according to the value
571573
break;
572574

573575
default:
574-
sort($data);
575-
return $data; //sort arrays in descending order
576+
sort($data); // sort arrays in ascending order
576577
break;
577578
}
579+
580+
return $data;
578581
}
579582

580583
/**
@@ -1162,7 +1165,7 @@ static public function platformIcon($platform = null, $os_name = null)
11621165
$os_name = Str::lower($os_name);
11631166

11641167
// set path
1165-
$path = self::stringReplacer( __DIR__ );
1168+
$path = self::stringReplacer( __DIR__ ) . DIRECTORY_SEPARATOR;
11661169

11671170
// Create items data set
11681171
$dataSet = [
@@ -1199,7 +1202,7 @@ static public function platformIcon($platform = null, $os_name = null)
11991202
static public function paymentIcon($payment = null)
12001203
{
12011204
// set path
1202-
$path = self::stringReplacer( __DIR__ );
1205+
$path = self::stringReplacer( __DIR__ ) . DIRECTORY_SEPARATOR;
12031206

12041207
// Create items data set
12051208
$dataSet = [

Tests/cookie.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
TameCookie()->get('cookie_name'),
2828

2929
Cookie::forget('cookie_name2'),
30-
31-
30+
3231
Cookie::expire('cookie_name2'),
3332
);

Tests/currency.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
dd(
99

10-
NumberToWords::text(1205435349345443534),
10+
NumberToWords::iso('nga')->text(1205435349345443534, true),
1111

12-
NumberToWords::text(455987.09, 'nga', true),
12+
NumberToWords::cents(true)->iso('nga')->text(455987.09),
1313

14-
NumberToWords::text(34590323, 'FRA', true),
14+
NumberToWords::cents(true)->iso('FRA')->text(34590323),
1515

16-
NumberToWords::text('120.95', 'tUr', true),
16+
NumberToWords::cents(true)->iso('TUR')->text('120.953'),
1717

18-
NumberToWords::text(1999),
18+
NumberToWords()->cents(false)->text(1999),
1919

20-
// NumberToWords::CurrencyNames()
20+
// NumberToWords()->CurrencyNames()
2121

2222
);

Tests/password.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
bcrypt('testPassword'),
1919

20-
Hash::check('testPassword', '$2y$10$Frh7yG3.qnGdQ9Hd8OK/y.aBWXFLiFD3IWqUjIWWodUhzIVF3DpT6')
20+
Hash::check('testPassword', '$2y$10$Frh7yG3.qnGdQ9Hd8OK/y.aBWXFLiFD3IWqUjIWWodUhzIVF3DpT6'),
21+
22+
// default php password verify function
23+
password_verify('testPassword', '$2y$10$Frh7yG3.qnGdQ9Hd8OK/y.aBWXFLiFD3IWqUjIWWodUhzIVF3DpT6')
2124
);
2225

Tests/test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
// ], 'Tests/en.php');
5050

5151

52+
$svg = Tame::platformIcon('windows');
53+
54+
include $svg;
55+
56+
echo "<img src='$svg'>";
57+
5258
dd(
5359
Tame::platformIcon('windows'),
5460

Tests/time.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@
4242
$time3->greetings(),
4343

4444
Time::getGlobalTimeZone(),
45+
46+
// Time::allTimezone(),
4547

4648
);

Traits/NumberToWordsTraits.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ trait NumberToWordsTraits
8989

9090
/**
9191
* All currency
92+
* - Country <iso-3></iso-3>
9293
*
9394
* @return array
9495
*/

0 commit comments

Comments
 (0)