Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit 6723504

Browse files
committed
updated use database
1 parent fa88dbb commit 6723504

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

Router/view.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PhpSlides\Router;
44

5-
use component;
5+
use function component;
66
use PhpSlides\Core\Foundation\Application;
77

88
/**
@@ -35,7 +35,7 @@ final public static function render (string $view, mixed ...$props): mixed
3535
{
3636
// split :: into array and extract the folder and files
3737
$file = preg_replace('/(::)|::/', '/', $view);
38-
$file = strtolower(trim($file, '\/\/'));
38+
$file = trim($file, '\/\/');
3939
$file_uri = Application::$viewsDir . $file;
4040
header('Content-Type: text/html');
4141

src/Database/Connection.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ static function connect()
3939
static::$user = getenv('DB_USERNAME');
4040
static::$db_type = getenv('DB_CONNECTION');
4141
static::$password = getenv('DB_PASSWORD');
42+
static::$db_base = getenv('DB_BASENAME') ?: 'php_slides';
4243

4344
// Construct DSN (Data Source Name) for the database connection
4445
DB::$dsn = sprintf(
4546
'%s:host=%s;port=%s;dbname=%s',
4647
static::$db_type,
4748
static::$host,
49+
static::$host,
4850
static::$port,
49-
'php_slides',
51+
static::$db_base,
5052
);
5153

5254
// Set the user and password for the database connection
@@ -74,7 +76,7 @@ static function reconnect()
7476
static::$db_type,
7577
static::$host,
7678
static::$port,
77-
'SchemaDb',
79+
static::$db_base,
7880
);
7981
}
8082

src/Database/Forgery.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ abstract class Forgery extends MeekroORM
2222
*/
2323
public static ?string $_connect_error = null;
2424

25+
/**
26+
* @var string $_dbname
27+
* Define the database name to use in reference to this class
28+
*/
29+
public static string $_dbname;
30+
2531
/**
2632
* Initialize the current table in using non-static mode.
2733
*

src/Forgery/Forge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected static function table ($db_name)
6060

6161
try
6262
{
63-
DB::useDB(self::format($db_name));
63+
DB::useDB(getenv('DB_BASENAME') ?: self::format($db_name));
6464
$all_class = [];
6565

6666
foreach (glob(Application::$basePath . "App/Forgery/$db_name/*") as $value)

src/Parser/ORMParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ORMParser extends Forge
2626
* format `Namespace\Database\ClassName`.
2727
* @return string The formatted table name, derived from the class name.
2828
*/
29-
public function parse (string $class)
29+
public function parse(string $class)
3030
{
3131
// Extract the segments of the class namespace.
3232
$name = explode('\\', $class);
@@ -38,7 +38,7 @@ public function parse (string $class)
3838
$name = static::format(end($name));
3939

4040
// Set the active database to the parsed database name.
41-
DB::useDB($db_name);
41+
DB::useDB($class::$_dbname ?? $db_name);
4242

4343
// Return the table name for ORM use.
4444
return $name;

0 commit comments

Comments
 (0)