Skip to content

Commit fd28d4d

Browse files
author
Fredrick Peter
committed
Code upgrade - Usage is same
1 parent ed20ca9 commit fd28d4d

File tree

7 files changed

+222
-183
lines changed

7 files changed

+222
-183
lines changed

Env.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Exception;
88
use Dotenv\Dotenv;
9+
use Tamedevelopers\Support\Tame;
910
use Tamedevelopers\Support\Constant;
1011
use Tamedevelopers\Support\Capsule\Manager;
1112
use Tamedevelopers\Support\Traits\ServerTrait;
@@ -142,8 +143,11 @@ static public function loadOrFail($path = null)
142143
*/
143144
static public function createOrIgnore()
144145
{
145-
// file to file
146-
$pathToFile = self::formatWithBaseDirectory('.env');
146+
// file to .env
147+
$envPath = self::formatWithBaseDirectory('.env');
148+
149+
// file env.example
150+
$envExamplePath = self::formatWithBaseDirectory('.env.example');
147151

148152
// when system path is empty
149153
if(empty(self::$sym_path)){
@@ -153,10 +157,17 @@ static public function createOrIgnore()
153157
// only attempt to create file if direcotry if valid
154158
if(is_dir(self::$sym_path)){
155159
// if file doesn't exist and not a directory
156-
if(!file_exists($pathToFile) && !is_dir($pathToFile)){
160+
if(!Tame::exists($envPath)){
161+
162+
// Write the contents to the new file
163+
file_put_contents($envPath, self::envTxt());
164+
}
165+
166+
// if file doesn't exist and not a directory
167+
if(!Tame::exists($envExamplePath)){
157168

158169
// Write the contents to the new file
159-
file_put_contents($pathToFile, self::envTxt());
170+
file_put_contents($envExamplePath, self::envTxt());
160171
}
161172
}
162173
}

Tame.php

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
namespace Tamedevelopers\Support;
66

7-
use ZipArchive;
87
use Tamedevelopers\Support\Str;
98
use Tamedevelopers\Support\Server;
109
use Tamedevelopers\Support\Traits\TameTrait;
1110

12-
1311
/**
1412
* @see \Tamedevelopers\Support\Str
1513
* @see \Tamedevelopers\Support\Server
@@ -81,13 +79,14 @@ static public function class_exists($class, callable $function = null)
8179
/**
8280
* Check if at least one class exists
8381
*
84-
* @param array $classNames Array of class names to check
82+
* @param string|array $classNames Array of class names to check
8583
* @return bool True if at least one class exists, false otherwise
8684
*/
87-
static public function checkAnyClassExists(array $classNames)
85+
static public function checkAnyClassExists(...$classNames)
8886
{
89-
foreach ($classNames as $className) {
90-
if (class_exists($className)) {
87+
$classNames = Str::flattenValue($classNames);
88+
foreach ($classNames as $name) {
89+
if (class_exists($name)) {
9190
return true;
9291
}
9392
}
@@ -245,57 +244,6 @@ static public function sizeToBytes($size = '1mb')
245244
return $size > self::KB ? $size : $size * self::KB;
246245
}
247246

248-
/**
249-
* Unzip a file or folder.
250-
*
251-
* @param string $sourcePath
252-
* @param string $destination
253-
* @return bool
254-
*/
255-
static public function unzip($sourcePath, $destination)
256-
{
257-
// If it's a zip file, call the unzipFile function
258-
if (pathinfo($sourcePath, PATHINFO_EXTENSION) === 'zip') {
259-
return self::unzipFile($sourcePath, $destination);
260-
}
261-
262-
// If it's a folder, call the unzipFolder function
263-
if (is_dir($sourcePath)) {
264-
return self::unzipFolder($sourcePath, $destination);
265-
}
266-
267-
return false; // Unsupported file type
268-
}
269-
270-
/**
271-
* Zip a file or folder.
272-
*
273-
* @param string $sourcePath The path to the file or folder to zip.
274-
* @param string $destinationZip The path for the resulting zip file.
275-
* @return bool True if the zip operation was successful, false otherwise.
276-
*/
277-
static public function zip($sourcePath, $destinationZip)
278-
{
279-
// If it's a folder, call the zipFolder function
280-
if (is_dir($sourcePath)) {
281-
return self::zipFolder($sourcePath, $destinationZip);
282-
}
283-
284-
// If it's a file, create a zip containing just that file
285-
$zip = new ZipArchive();
286-
287-
if ($zip->open($destinationZip, ZipArchive::CREATE) !== true) {
288-
return false;
289-
}
290-
291-
// Add the file to the zip
292-
$zip->addFile($sourcePath, basename($sourcePath));
293-
294-
$zip->close();
295-
296-
return file_exists($destinationZip);
297-
}
298-
299247
/**
300248
* Get file modification time
301249
*

Tests/country.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77

88
// helper function
9-
// country();
9+
// TameCountry();
1010

1111
// Country::countryIso3()
1212

1313
dd(
1414

15-
country()->getTimeZone("Africa/Addis_Ababa"),
15+
TameCountry()->getTimeZone("Africa/Addis_Ababa"),
1616

17-
country()->getCaptchaLocale('ar'),
17+
TameCountry()->getCaptchaLocale('ar'),
1818

1919
Country::getCountryIso3('NGA')
2020
);

Time.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -441,63 +441,65 @@ static private function carbonInstance()
441441

442442
/**
443443
* Handle the calls to non-existent methods.
444-
* @param string|null $name
444+
* @param string|null $method
445445
* @param mixed $args
446446
* @return mixed
447447
*/
448-
static private function nonExistMethod($name = null, $args = null)
448+
static private function nonExistMethod($method = null, $args = null)
449449
{
450450
// convert to lowercase
451-
$name = Str::lower($name);
451+
$name = Str::lower($method);
452452

453453
switch ($name) {
454454
case in_array($name, ['tojs', 'jstimer']):
455-
$className = 'toJsTimer';
455+
$method = 'toJsTimer';
456456
break;
457457

458458
case in_array($name, ['time', 'gettimes', 'gettime']):
459-
$className = 'getDate';
459+
$method = 'getDate';
460460
break;
461461

462462
case in_array($name, ['hours', 'hr', 'hrs', 'gethr', 'gethours']):
463-
$className = 'getHour';
463+
$method = 'getHour';
464464
break;
465465

466466
case in_array($name, ['getseconds', 'getsec', 'sec', 's']):
467-
$className = 'getSecond';
467+
$method = 'getSecond';
468468
break;
469469

470470
case in_array($name, ['min', 'mins', 'getminute', 'getminutes', 'getmins']):
471-
$className = 'getMin';
471+
$method = 'getMin';
472472
break;
473473

474474
case in_array($name, ['getday', 'getdays', 'getd', 'day', 'days']):
475-
$className = 'getDay';
475+
$method = 'getDay';
476476
break;
477477

478478
case in_array($name, ['getweek', 'getweeks', 'getw']):
479-
$className = 'getWeek';
479+
$method = 'getWeek';
480480
break;
481481

482482
case in_array($name, ['getmonths', 'getmonth', 'getm']):
483-
$className = 'getMonth';
483+
$method = 'getMonth';
484484
break;
485485

486486
case in_array($name, ['getyr', 'getyears', 'getyear', 'year', 'years', 'yr', 'yrs', 'y']):
487-
$className = 'getYear';
487+
$method = 'getYear';
488488
break;
489489

490490
case $name === 'greetings':
491-
$className = 'greeting';
491+
$method = 'greeting';
492492
break;
493493

494494
default:
495-
$className = 'timeAgo';
495+
$method = 'timeAgo';
496496
break;
497497
}
498+
499+
// create instance of new static self
500+
$instance = new static(self::$date, self::$timezone);
498501

499-
// run
500-
return call_user_func_array([new static(), $className], $args);
502+
return $instance->$method(...$args);
501503
}
502504

503505
}

Traits/TameTrait.php

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
namespace Tamedevelopers\Support\Traits;
66

7-
use ZipArchive;
8-
use RecursiveIteratorIterator;
9-
use RecursiveDirectoryIterator;
10-
117

128
trait TameTrait{
139

@@ -209,99 +205,4 @@ static private function getSvgPath(?string $path = null)
209205
return self::stringReplacer(base_path()) . $path;
210206
}
211207

212-
/**
213-
* Unzip a zip file.
214-
*
215-
* @param string $file The path to the zip file.
216-
* @param string $destination The path to the destination directory where the contents will be extracted.
217-
* @return bool True if the unzip operation was successful, false otherwise.
218-
*/
219-
static private function unzipFile($file, $destination)
220-
{
221-
// Create object
222-
$zip = new ZipArchive();
223-
224-
// Open archive
225-
if ($zip->open($file) !== true) {
226-
return false;
227-
}
228-
229-
// Extract contents to destination directory
230-
$zip->extractTo(self::getBasePath($destination));
231-
232-
// Close archive
233-
$zip->close();
234-
235-
return true;
236-
}
237-
238-
/**
239-
* Zip a folder and its contents.
240-
*
241-
* @param string $sourceFolder The path to the folder to zip.
242-
* @param string $destinationZip The path for the resulting zip file.
243-
* @return bool True if the zip operation was successful, false otherwise.
244-
*/
245-
static private function zipFolder($sourceFolder, $destinationZip)
246-
{
247-
$zip = new ZipArchive();
248-
249-
if ($zip->open($destinationZip, ZipArchive::CREATE) !== true) {
250-
return false;
251-
}
252-
253-
$files = new RecursiveIteratorIterator(
254-
new RecursiveDirectoryIterator($sourceFolder),
255-
RecursiveIteratorIterator::LEAVES_ONLY
256-
);
257-
258-
foreach ($files as $name => $file) {
259-
if (!$file->isDir()) {
260-
$filePath = $file->getRealPath();
261-
$localPath = substr($filePath, strlen($sourceFolder) + 1);
262-
$zip->addFile($filePath, $localPath);
263-
}
264-
}
265-
266-
$zip->close();
267-
268-
return file_exists($destinationZip);
269-
}
270-
271-
/**
272-
* Unzip a folder and its contents.
273-
*
274-
* @param string $sourceFolder The path to the folder to unzip.
275-
* @param string $destination The path to the destination directory where the contents will be extracted.
276-
* @return bool True if the unzip operation was successful, false otherwise.
277-
*/
278-
static private function unzipFolder($sourceFolder, $destination)
279-
{
280-
// Ensure the destination directory exists
281-
if (!is_dir($destination)) {
282-
mkdir($destination, 0777, true);
283-
}
284-
285-
$files = new RecursiveIteratorIterator(
286-
new RecursiveDirectoryIterator($sourceFolder),
287-
RecursiveIteratorIterator::LEAVES_ONLY
288-
);
289-
290-
foreach ($files as $name => $file) {
291-
if (!$file->isDir()) {
292-
$filePath = $file->getRealPath();
293-
$localPath = substr($filePath, strlen($sourceFolder) + 1);
294-
$destinationPath = $destination . '/' . $localPath;
295-
// Ensure the destination directory for the file exists
296-
$destinationDir = dirname($destinationPath);
297-
if (!is_dir($destinationDir)) {
298-
mkdir($destinationDir, 0777, true);
299-
}
300-
copy($filePath, $destinationPath);
301-
}
302-
}
303-
304-
return true;
305-
}
306-
307208
}

0 commit comments

Comments
 (0)