Skip to content

Commit ef6e86e

Browse files
author
Fredrick Peter
committed
update
1 parent fe4d80b commit ef6e86e

File tree

4 files changed

+51
-28
lines changed

4 files changed

+51
-28
lines changed

Capsule/Manager.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ static public function envDummy()
5757
AWS_SECRET_ACCESS_KEY=
5858
AWS_DEFAULT_REGION=us-east-1
5959
AWS_BUCKET=
60+
AWS_URL=
6061
AWS_USE_PATH_STYLE_ENDPOINT=false
62+
63+
CLOUDINARY_SECRET_KEY=
64+
CLOUDINARY_KEY=
65+
CLOUDINARY_NAME=
66+
CLOUDINARY_URL=
67+
CLOUDINARY_SECURE=false
6168
6269
PUSHER_APP_ID=
6370
PUSHER_APP_KEY=

Collections/Collection.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace Tamedevelopers\Support;
5+
namespace Tamedevelopers\Support\Collections;
66

77
use ArrayAccess;
88
use Traversable;
99
use ArrayIterator;
1010
use IteratorAggregate;
11+
use Tamedevelopers\Support\Server;
1112

1213
class Collection implements IteratorAggregate, ArrayAccess
1314
{
@@ -25,7 +26,7 @@ class Collection implements IteratorAggregate, ArrayAccess
2526
*/
2627
public function __construct($items = [])
2728
{
28-
$this->items = $this->convertOnInit($items);
29+
$this->items = $items;
2930
}
3031

3132
/**
@@ -158,9 +159,7 @@ public function count(): int
158159
*/
159160
public function toArray()
160161
{
161-
return is_array($this->items)
162-
? $this->items
163-
: [];
162+
return Server::toArray($this->items);
164163
}
165164

166165
/**
@@ -170,7 +169,7 @@ public function toArray()
170169
*/
171170
public function toObject()
172171
{
173-
return json_decode( json_encode($this->items), false);
172+
return Server::toObject($this->items);
174173
}
175174

176175
/**
@@ -180,18 +179,7 @@ public function toObject()
180179
*/
181180
public function toJson()
182181
{
183-
return json_encode($this->items);
184-
}
185-
186-
/**
187-
* Convert data to an array on Initializaiton
188-
* @param mixed $items
189-
*
190-
* @return array
191-
*/
192-
private function convertOnInit(mixed $items = null)
193-
{
194-
return json_decode( json_encode($items), true);
182+
return Server::toJson($this->items);
195183
}
196184

197185
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Support Package For Tamedevelopers
3131
Prior to installing `support package` get the [Composer](https://getcomposer.org) dependency manager for PHP because it'll simplify installation.
3232

3333
```
34-
composer require peterson/database
34+
composer require tamedevelopers/support
3535
```
3636

3737

Tame.php

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,22 @@ static public function requireOnce($path)
173173
* Convert Bytes to Units
174174
*
175175
* @param float|int $bytes
176-
* @param mixed $format
177-
* [optional] Default is true --- UPPER CASE
176+
* @param bool $format
177+
* @param string|null $gb
178+
* @param string|null $mb
179+
* @param string|null $kb
178180
*
179181
* @return string
180182
*/
181-
static public function byteToUnit(float|int $bytes = 0, $format = true)
183+
static public function byteToUnit($bytes = 0, $format = true, $gb = 'GB', $mb = 'MB', $kb = 'KB')
182184
{
185+
$bytes = (int) $bytes;
183186
if ($bytes >= 1073741824){
184-
$bytes = round(($bytes / 1073741824)) . 'GB';
187+
$bytes = round(($bytes / 1073741824)) . $gb;
185188
} elseif ($bytes >= 1048576){
186-
$bytes = round(($bytes / 1048576)) . 'MB';
189+
$bytes = round(($bytes / 1048576)) . $mb;
187190
} elseif ($bytes >= 1024){
188-
$bytes = round(($bytes / 1024)) . 'KB';
191+
$bytes = round(($bytes / 1024)) . $kb;
189192
}
190193

191194
return $format ? $bytes : Str::lower($bytes);
@@ -199,7 +202,7 @@ static public function byteToUnit(float|int $bytes = 0, $format = true)
199202
*/
200203
static public function sizeToBytes($size = '1mb')
201204
{
202-
$size = Str::lower((string) $size);
205+
$size = Str::lower(str_replace(' ', '', (string) $size));
203206

204207
// Match the size and unit from the input string
205208
if (preg_match('/^(\d+(\.\d+)?)([kmg]b?)?$/', $size, $matches)) {
@@ -214,12 +217,16 @@ static public function sizeToBytes($size = '1mb')
214217
case 'gb':
215218
return (int) ($value * self::GB);
216219
default:
217-
// If no unit specified, default to kilobytes
220+
// If no unit specified, default to megabytes
218221
return (int) ($value * self::MB);
219222
}
220223
}
221224

222-
return false; // Invalid input
225+
// Invalid input
226+
$size = (int) $size;
227+
228+
// check if input is greter than 1kb, else default to 1KB
229+
return $size > self::KB ? $size : $size * self::KB;
223230
}
224231

225232
/**
@@ -1155,4 +1162,25 @@ static public function stringReplacer(?string $path = null)
11551162
return Server::cleanServerPath($path);
11561163
}
11571164

1165+
/**
1166+
* Check IF Internet is Available
1167+
*
1168+
* @return bool
1169+
*/
1170+
static public function isInternetAvailable()
1171+
{
1172+
// Use cURL to make a request
1173+
$request = curl_init('https://www.google.com');
1174+
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
1175+
curl_setopt($request, CURLOPT_TIMEOUT, 5);
1176+
curl_exec($request);
1177+
1178+
// Check the HTTP response code
1179+
$httpCode = curl_getinfo($request, CURLINFO_HTTP_CODE);
1180+
curl_close($request);
1181+
1182+
// HTTP code 200 means the request was successful
1183+
return $httpCode === 200;
1184+
}
1185+
11581186
}

0 commit comments

Comments
 (0)