Skip to content

Commit 73e0f21

Browse files
Server::config() frameworks support, Str::trim()update
1 parent 49a405e commit 73e0f21

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

src/Capsule/Artisan.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function run(array $argv): int
128128

129129
if (!isset(self::$commands[$base])) {
130130
Logger::error("Command \"{$commandInput}\" is not defined.\n\n");
131-
return 1;
131+
return 0;
132132
}
133133

134134
// Normalize entries to array of providers for this base command

src/Capsule/CommandHelper.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Tamedevelopers\Support\Str;
99
use Tamedevelopers\Support\Constant;
1010
use Tamedevelopers\Support\Capsule\Logger;
11+
use Tamedevelopers\Support\Process\HttpRequest;
1112

1213

1314
class CommandHelper
@@ -18,17 +19,34 @@ class CommandHelper
1819
*/
1920
protected $conn;
2021

22+
/**
23+
* The database connector instance.
24+
* @var bool|null
25+
*/
26+
protected $isConsole;
27+
2128
/**
2229
* Constructor
2330
* @param \Tamedevelopers\Database\Connectors\Connector|null $conn
2431
*/
2532
public function __construct($conn = null)
2633
{
27-
if(class_exists('Tamedevelopers\Database\DB') && is_null($conn)){
28-
$conn = \Tamedevelopers\Database\DB::connection();
34+
$instance = "Tamedevelopers\Database\DB";
35+
if(class_exists($instance) && is_null($conn)){
36+
$conn = $instance::connection();
2937
}
3038

3139
$this->conn = $conn;
40+
$this->isConsole = $this->isConsole();
41+
}
42+
43+
/**
44+
* Checking for incoming CLI type
45+
* @param bool
46+
*/
47+
protected function isConsole(): bool
48+
{
49+
return HttpRequest::runningInConsole();
3250
}
3351

3452
/**
@@ -40,8 +58,11 @@ protected function checkConnection($conn): void
4058
$checkConnection = $conn->dbConnection();
4159

4260
if($checkConnection['status'] != Constant::STATUS_200){
43-
$this->error($checkConnection['message']);
44-
exit();
61+
if($this->isConsole()){
62+
$this->error($checkConnection['message']);
63+
exit(1);
64+
}
65+
return;
4566
}
4667
}
4768

@@ -72,7 +93,10 @@ protected function forceChecker(): void
7293
if ($this->isProduction()) {
7394
if (!$force) {
7495
$this->error("You are in production! Use [--force|-f] flag, to run this command.");
75-
exit(1);
96+
if($this->isConsole()){
97+
exit(1);
98+
}
99+
return;
76100
}
77101
}
78102
}
@@ -271,8 +295,8 @@ protected function extractTableName($migration = null)
271295
*/
272296
protected function confirm(string $question, bool $default = false): bool
273297
{
274-
$yesNo = $default ? 'Y/n' : 'y/N';
275-
$answer = readline("{$question} [{$yesNo}]: ");
298+
$yesNo = $default ? 'y/n' : 'Y/N';
299+
$answer = readline("{$question} ({$yesNo}): ");
276300

277301
if (empty($answer)) {
278302
return $default;

src/Server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Server{
1919
/**
2020
* Get the value of a configuration option.
2121
*
22-
* @param mixed $key
22+
* @param mixed $key
2323
* The configuration key in dot notation (e.g., 'database.connections.mysql')
2424
*
2525
* @param mixed $default
@@ -92,7 +92,7 @@ public static function config($key, $default = null, string $base_folder = 'conf
9292
}
9393

9494
// try merging data if an array
95-
if(!empty($config) && is_array($default)){
95+
if(!empty($config) && is_array($config) && is_array($default)){
9696
return array_merge($config, $default);
9797
}
9898

src/Str.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ public static function slugify(string $value, string $separator = '-')
875875
*/
876876
public static function trim($string = null, string $characters = " \n\r\t\v\0")
877877
{
878+
$string = is_array($string) ? $string[0] ?? null : $string;
878879
return trim((string) $string, $characters);
879880
}
880881

0 commit comments

Comments
 (0)