Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/tests export-ignore
/.github export-ignore
/.phpunit.cache export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.phpunit.result.cache export-ignore
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"homepage": "https://github.com/PhpSlides",
"type": "library",
"license": "MIT",
"keywords": [ "framework", "phpslides" ],
"keywords": ["framework", "phpslides"],
"support": {
"issues": "https://github.com/PhpSlides/framework/issues",
"source": "https://github.com/PhpSlides/framework"
Expand All @@ -31,22 +31,23 @@
},
"autoload": {
"psr-4": {
"PhpSlides\\": [ "src/Exception/" ],
"PhpSlides\\Src\\": [ "src/" ],
"PhpSlides\\Router\\": [ "Router/" ]
"PhpSlides\\": "src/Exception/",
"PhpSlides\\Src\\": "src/",
"PhpSlides\\Router\\": "Router/"
},
"files": [ "src/Bootstrap/App.php" ]
"files": ["src/Bootstrap/App.php"]
},
"autoload-dev": {
"psr-4": {
"PhpSlides\\Tests\\": "tests/"
"PhpSlides\\Tests\\": "tests/tests/"
}
},
"config": {
"preferred-install": "dist"
},
"scripts": {
"test": "vendor/bin/phpunit"
"test": "vendor/bin/phpunit",
"phpunit": "php vendor/bin/phpunit"
},
"minimum-stability": "stable",
"prefer-stable": true
Expand Down
28 changes: 13 additions & 15 deletions src/Cli/Configure.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php declare(strict_types=1);


namespace PhpSlides\Src\Cli;

trait Configure
{
public static function bootstrap ()
{
if (php_sapi_name() == 'cli')
{
// Mock necessary $_SERVER variables
$_SERVER['REQUEST_URI'] ??= '/';
$_SERVER['REQUEST_METHOD'] ??= 'GET';
$_SERVER['HTTP_HOST'] ??= 'localhost';
$_SERVER['SERVER_NAME'] ??= 'localhost';
$_SERVER['SERVER_PORT'] ??= '80';
$_SERVER['HTTPS'] ??= 'off';
}
}
}
protected static function bootstrap()
{
if (php_sapi_name() == 'cli') {
// Mock necessary $_SERVER variables
$_SERVER['REQUEST_URI'] ??= '/';
$_SERVER['REQUEST_METHOD'] ??= 'GET';
$_SERVER['HTTP_HOST'] ??= 'localhost';
$_SERVER['SERVER_NAME'] ??= 'localhost';
$_SERVER['SERVER_PORT'] ??= '80';
$_SERVER['HTTPS'] ??= 'off';
}
}
}
71 changes: 28 additions & 43 deletions src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Closure;
use PhpSlides\Router\Route;
use PhpSlides\Src\Http\Request;
use PhpSlides\Src\Cli\Configure;
use PhpSlides\Src\Forgery\Forge;
use PhpSlides\Src\Logger\Logger;
use PhpSlides\Src\Logger\DBLogger;
Expand All @@ -30,12 +29,12 @@
*/
class Application extends Controller implements ApplicationInterface
{
use \PhpSlides\Src\Cli\Configure;
use Configuration;
use Logger;
use DBLogger
{
Logger::log insteadof DBLogger;
DBLogger::log as db_log;
use DBLogger {
Logger::log insteadof DBLogger;
DBLogger::log as db_log;
}

/**
Expand Down Expand Up @@ -97,37 +96,32 @@ class Application extends Controller implements ApplicationInterface
*
* @return self Returns an instance of the Application class.
*/
private static function configure (): void
private static function configure(): void
{
if (php_sapi_name() == 'cli')
{
Configure::bootstrap();
if (php_sapi_name() == 'cli') {
static::bootstrap();

self::$request_uri = '/';
self::$basePath = './tests/';
}
else if (php_sapi_name() == 'cli-server')
{
} elseif (php_sapi_name() == 'cli-server') {
self::$request_uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),
);
self::$basePath = '';
}
else
{
} else {
self::$request_uri = urldecode(
parse_url(
$_REQUEST['uri'] ?? $_SERVER['REQUEST_URI'],
PHP_URL_PATH,
),
parse_url(
$_REQUEST['uri'] ?? $_SERVER['REQUEST_URI'],
PHP_URL_PATH,
),
);

$find = '/src/routes/render.php';
$self = $_SERVER['PHP_SELF'];

self::$basePath = strrpos($self, $find)
? substr_replace($self, '/', strrpos($self, $find), strlen($find))
: '../../';
? substr_replace($self, '/', strrpos($self, $find), strlen($find))
: '../../';
}

$req = new Request();
Expand All @@ -141,7 +135,7 @@ private static function configure (): void
*
* @return void
*/
private static function paths (): void
private static function paths(): void
{
self::$configsDir = self::$basePath . 'src/configs/';
self::$viewsDir = self::$basePath . 'src/resources/views/';
Expand All @@ -154,15 +148,15 @@ private static function paths (): void
*
* @return void
*/
public function create (): void
public function create(): void
{
self::configure();
self::paths();

$loader = new FileLoader();
$loader
->load(__DIR__ . '/../Config/env.config.php')
->load(__DIR__ . '/../Config/config.php');
->load(__DIR__ . '/../Config/env.config.php')
->load(__DIR__ . '/../Config/config.php');

session_start();

Expand All @@ -171,11 +165,9 @@ public function create (): void

$sid = session_id();

if (getenv('HOT_RELOAD') == 'true')
{
Route::post("/hot-reload-a$sid", fn () => (new HotReload())->reload());
Route::get("/hot-reload-a$sid/worker", function () use ($sid): string
{
if (getenv('HOT_RELOAD') == 'true') {
Route::post("/hot-reload-a$sid", fn() => (new HotReload())->reload());
Route::get("/hot-reload-a$sid/worker", function () use ($sid): string {
$addr = self::$REMOTE_ADDR . "/hot-reload-a$sid";
header('Content-Type: application/javascript');

Expand All @@ -184,22 +176,18 @@ public function create (): void
Render::WebRoute();
}

try
{
try {
Connection::init();
DB::query('SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA');
}
catch ( \Exception $e )
{
} catch (\Exception $e) {
Database::$_connect_error = $e->getMessage();
goto EXECUTION;
}
new Forge();
new Autoloader();

EXECUTION:
try
{
try {
$loader->load(__DIR__ . '/../Globals/Functions.php');

$config_file = self::config_file();
Expand All @@ -209,14 +197,11 @@ public function create (): void
header("Content-Type: text/html; charset=$charset");

self::config();
}
catch ( \Exception $e )
{
} catch (\Exception $e) {
http_response_code(500);
static::log();

if (function_exists('ExceptionHandler'))
{
if (function_exists('ExceptionHandler')) {
call_user_func('ExceptionHandler', $e);
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_NAME = 'PhpSlides'
Loading