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

Commit d3267c3

Browse files
committed
updated files & folders structure
1 parent b303513 commit d3267c3

File tree

5 files changed

+107
-120
lines changed

5 files changed

+107
-120
lines changed

src/Database/Connection.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class Connection
1818
public static $host;
1919
public static $port;
2020
public static $user;
21-
public static $db_name;
2221
public static $db_type;
2322
public static $password;
2423

@@ -32,23 +31,22 @@ class Connection
3231
*
3332
* @return void
3433
*/
35-
static function connect ()
34+
static function connect()
3635
{
3736
// Set connection parameters from environment variables
38-
static::$port = getenv('DB_PORT') ?: 3306;
39-
static::$host = getenv('DB_HOST') ?: '0.0.0.0';
40-
static::$user = getenv('DB_USER') ?: 'root';
41-
static::$db_name = getenv('DB_BASE') ?: '';
42-
static::$db_type = getenv('DB_CONN') ?: 'mysql';
43-
static::$password = getenv('DB_PASS') ?: '';
37+
static::$port = getenv('DB_PORT');
38+
static::$host = getenv('DB_HOST');
39+
static::$user = getenv('DB_USERNAME');
40+
static::$db_type = getenv('DB_CONNECTION');
41+
static::$password = getenv('DB_PASSWORD');
4442

4543
// Construct DSN (Data Source Name) for the database connection
4644
DB::$dsn = sprintf(
47-
'%s:host=%s;port=%s;dbname=%s',
48-
static::$db_type,
49-
static::$host,
50-
static::$port,
51-
static::$db_name,
45+
'%s:host=%s;port=%s;dbname=%s',
46+
static::$db_type,
47+
static::$host,
48+
static::$port,
49+
'php_slides',
5250
);
5351

5452
// Set the user and password for the database connection
@@ -65,18 +63,18 @@ static function connect ()
6563
*
6664
* @return void
6765
*/
68-
static function reconnect ()
66+
static function reconnect()
6967
{
7068
// Disconnect the current database connection
7169
DB::disconnect();
7270

7371
// Recreate the DSN and reconnect with the new parameters
7472
DB::$dsn = sprintf(
75-
'%s:host=%s;port=%s;dbname=%s',
76-
static::$db_type,
77-
static::$host,
78-
static::$port,
79-
static::$db_name,
73+
'%s:host=%s;port=%s;dbname=%s',
74+
static::$db_type,
75+
static::$host,
76+
static::$port,
77+
'SchemaDb',
8078
);
8179
}
8280

@@ -89,10 +87,10 @@ static function reconnect ()
8987
*
9088
* @return void
9189
*/
92-
static function init ()
90+
static function init()
9391
{
94-
DB::$host = static::$host ?? getenv('DB_HOST') ?: 3306;
95-
DB::$user = static::$user ?? getenv('DB_USER') ?: 'root';
96-
DB::$password = static::$password ?? getenv('DB_PASS') ?: '';
92+
DB::$host = static::$host ?? getenv('DB_HOST');
93+
DB::$user = static::$user ?? getenv('DB_USERNAME');
94+
DB::$password = static::$password ?? getenv('DB_PASSWORD');
9795
}
98-
}
96+
}

src/Database/Database.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/Database/Forgery.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace PhpSlides\Core\Database;
4+
5+
use MeekroORM;
6+
use PhpSlides\Core\Parser\ORMParser;
7+
8+
/**
9+
* Abstract class for managing database operations with MeekroORM.
10+
*
11+
* The `Forgery` class extends the `MeekroORM` third party app to manage database
12+
* interactions, such as queries and connection handling, within the context
13+
* of the PhpSlides framework. It allows dynamic initialization of tables
14+
* and provides a mechanism for debugging connection errors.
15+
*/
16+
abstract class Forgery extends MeekroORM
17+
{
18+
/**
19+
* @var string|null $_connect_error
20+
* Stores connection error messages, if any occur during database connection.
21+
* The error is captured and made available for debugging purposes.
22+
*/
23+
public static ?string $_connect_error = null;
24+
25+
/**
26+
* Initialize the current table in using non-static mode.
27+
*
28+
* The constructor invokes the `static()` method to initialize the current
29+
* table. It ensures that the class is configured for ORM operations,
30+
* including setting up the table name.
31+
*/
32+
public function __construct()
33+
{
34+
static::static();
35+
}
36+
37+
/**
38+
* Initialize the current table in using static mode.
39+
*
40+
* This static method parses the class name using the `ORMParser` to
41+
* determine the table name and other relevant details. It assigns the
42+
* table name to the static property `$_tablename` for use with MeekroORM.
43+
*
44+
* @return void
45+
*/
46+
public static function static()
47+
{
48+
// Parse the class name using the ORMParser to determine the table name
49+
$parsed = (new ORMParser())->parse(get_called_class());
50+
51+
// Assign the parsed table name to the static property $_tablename
52+
static::$_tablename = $parsed;
53+
}
54+
}

src/Exception/Exception.php

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Exception as DefaultException;
77
use PhpSlides\Interface\SlidesException;
88

9-
109
/**
1110
* The Exception class provides enhanced exception handling for the PhpSlides application.
1211
*/
@@ -19,26 +18,23 @@ class Exception extends DefaultException implements SlidesException
1918
*
2019
* @return string A detailed error message.
2120
*/
22-
public function getDetailedMessage (): string
21+
public function getDetailedMessage(): string
2322
{
2423
$trace = $this->filterStackTrace();
2524

26-
if (!empty($trace))
27-
{
25+
if (!empty($trace)) {
2826
$file = $trace[0]['file'];
2927
$line = $trace[0]['line'];
30-
}
31-
else
32-
{
28+
} else {
3329
$file = $this->getFile();
3430
$line = $this->getLine();
3531
}
3632

3733
return sprintf(
38-
'Error: %s in %s on line %d',
39-
$this->getMessage(),
40-
$file,
41-
$line,
34+
'Error: %s in %s on line %d',
35+
$this->getMessage(),
36+
$file,
37+
$line,
4238
);
4339
}
4440

@@ -47,55 +43,50 @@ public function getDetailedMessage (): string
4743
*
4844
* @return array The filtered stack trace.
4945
*/
50-
public function filterStackTrace (): array
46+
public function filterStackTrace(): array
5147
{
5248
/**
5349
* This filter removes all file paths that come from the vendor folders.
5450
*/
5551

56-
/*
52+
5753
$majorFilter = array_filter($this->getTrace(), function ($item) {
5854
$ss = strpos($item['file'], '/vendor/') === false;
5955
$sss = strpos($item['file'], '\vendor\\') === false;
6056

6157
return $ss && $sss === true;
6258
});
63-
*/
59+
6460

6561
/**
6662
* This filter adds only file paths from the vendor folders.
6763
*/
6864

69-
/*
70-
$minorFilter = array_filter($this->getTrace(), function ($item) {
71-
$ss = strpos($item['file'], '/vendor/') !== false;
72-
$sss = strpos($item['file'], '\vendor\\') !== false;
65+
$minorFilter = array_filter($this->getTrace(), function ($item) {
66+
$ss = strpos($item['file'], '/vendor/') !== false;
67+
$sss = strpos($item['file'], '\vendor\\') !== false;
7368

74-
return $ss || $sss === true;
75-
});
76-
*/
69+
return $ss || $sss === true;
70+
});
7771

7872
/**
7973
* Create a new array and merge them together.
8074
* Major filters first, then the minor filters.
8175
*/
8276

83-
/*
84-
$majorFilterValue = array_values($majorFilter);
85-
$minorFilterValue = array_values($minorFilter);
86-
$newFilter = array_merge($majorFilterValue, $minorFilterValue);
87-
*/
77+
$majorFilterValue = array_values($majorFilter);
78+
$minorFilterValue = array_values($minorFilter);
79+
$newFilter = array_merge($majorFilterValue, $minorFilterValue);
8880

8981
/**
9082
* Replace generated views files to the corresponding view
9183
*/
92-
$newFilter = array_map(function ($item)
93-
{
84+
$newFilter = array_map(function ($item) {
9485
$item['file'] = str_replace('.g.php', '.php', $item['file']);
9586
$item['file'] = str_replace('.g.psl', '.psl', $item['file']);
9687

9788
return $item;
98-
}, $this->getTrace());
89+
}, $newFilter);
9990

10091
return $newFilter;
10192
}
@@ -105,12 +96,11 @@ public function filterStackTrace (): array
10596
*
10697
* @return string The file path.
10798
*/
108-
public function getFilteredFile (): string
99+
public function getFilteredFile(): string
109100
{
110101
$trace = $this->filterStackTrace();
111102

112-
if (!empty($trace))
113-
{
103+
if (!empty($trace)) {
114104
return $trace[0]['file'];
115105
}
116106
return $this->getFile();
@@ -121,11 +111,10 @@ public function getFilteredFile (): string
121111
*
122112
* @return int The line number.
123113
*/
124-
public function getFilteredLine (): int
114+
public function getFilteredLine(): int
125115
{
126116
$trace = $this->filterStackTrace();
127-
if (!empty($trace))
128-
{
117+
if (!empty($trace)) {
129118
return $trace[0]['line'];
130119
}
131120
return $this->getLine();
@@ -138,17 +127,17 @@ public function getFilteredLine (): int
138127
* @param int $linesAfter The number of lines after the error line to include.
139128
* @return array The code snippet.
140129
*/
141-
public function getCodeSnippet ($linesBefore = 10, $linesAfter = 10): array
130+
public function getCodeSnippet($linesBefore = 10, $linesAfter = 10): array
142131
{
143132
$file = $this->getFilteredFile() ?? $this->getFile();
144133
$line = $this->getFilteredLine() ?? $this->getLine();
145134

146135
(new FileLoader())->load(__DIR__ . '/../Globals/Chunks/codeSnippets.php');
147136
return getCodeSnippet(
148-
file: $file,
149-
line: $line,
150-
linesBefore: $linesBefore,
151-
linesAfter: $linesAfter,
137+
file: $file,
138+
line: $line,
139+
linesBefore: $linesBefore,
140+
linesAfter: $linesAfter,
152141
);
153142
}
154143
}

src/Exception/template/index.php

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

1818
<script>
1919
document.head.innerHTML = ''
20-
document.title = 'Parse Error - <?php echo $message; ?>'
20+
document.title = 'PhpSlides - Uncaught Exception'
2121
</script>
2222

2323
<style type="text/css" media="all">
@@ -117,7 +117,7 @@
117117

118118
<body>
119119
<header>
120-
<h3>Parse Error</h3>
120+
<h3>Uncaught Exception</h3>
121121
<span><?php echo $message; ?></span>
122122
</header>
123123

0 commit comments

Comments
 (0)