Initial Class tryout

This commit is contained in:
Kilian Hofmann 2024-07-20 12:30:53 +02:00
parent ab1df63788
commit 87d949361e
7 changed files with 108 additions and 1 deletions

35
exam/.htaccess Normal file
View File

@ -0,0 +1,35 @@
RewriteEngine On
##
## You may need to uncomment the following line for some hosting environments,
## if you have installed to a subdirectory, enter the name here also.
##
RewriteBase /phpCourse/exam
##
## Black listed folders
##
RewriteRule ^phpCourse/exam/config/.* index.php [L,NC]
RewriteRule ^phpCourse/exam/vendor/.* index.php [L,NC]
RewriteRule ^phpCourse/exam/routes/.* index.php [L,NC]
##
## White listed folders
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/api/docs/.*
RewriteCond %{REQUEST_FILENAME} !/pages/.*
RewriteRule !^index.php index.php [L,NC]
##
## Block all PHP files, except index
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !^index.php index.php [L,NC]
##
## Standard routes
##
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

11
exam/Api/Login/Login.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace Api\Login;
class Login
{
public function get()
{
echo "LOGIN HANDLER GET";
}
}

42
exam/index.php Normal file
View File

@ -0,0 +1,42 @@
<?php
// Enable Errors
ini_set("display_errors", 1);
ini_set("default_charset", "utf-8");
ini_set('session.cookie_httponly', 1);
ini_set('session.cookie_secure', 1);
ini_set('session.use_only_cookies', 1);
error_reporting(E_ALL);
// Load composer Autoloader
require_once __DIR__ . "/vendor/autoload.php";
// Namespaces
use Pecee\SimpleRouter\SimpleRouter;
use Pecee\SimpleRouter\Handlers\EventHandler;
use Pecee\SimpleRouter\Event\EventArgument;
use Pecee\SimpleRouter\Route\ILoadableRoute;
use Pecee\SimpleRouter\Route\IGroupRoute;
// Router base path
$basePath = '/phpCourse/exam/';
// Router event handler for prepending base path
$eventHandler = new EventHandler();
$eventHandler->register(EventHandler::EVENT_ADD_ROUTE, function (EventArgument $event) use ($basePath) {
$route = $event->route;
// Skip routes added by group as these will inherit the url
if ($event->isSubRoute) {
return;
}
// Prepend based on what type of Route
switch (true) {
case $route instanceof ILoadableRoute:
$route->prependUrl($basePath);
break;
case $route instanceof IGroupRoute:
$route->prependPrefix($basePath);
break;
}
});
// Add the handler
SimpleRouter::addEventHandler($eventHandler);
// Load external routes file
require_once __DIR__ . '/routes/routes.php';
// Start the routing
SimpleRouter::start();

3
exam/routes/.htaccess Normal file
View File

@ -0,0 +1,3 @@
Order deny,allow
Deny from all
Allow from 127.0.0.1

12
exam/routes/routes.php Normal file
View File

@ -0,0 +1,12 @@
<?php
use Pecee\SimpleRouter\SimpleRouter;
use Api\Login\Login;
SimpleRouter::get('/', function () {
return 'Hello world';
});
$l = new Login();
SimpleRouter::get("/api/login", [Login::class, 'get']);

3
exam/vendor/.htaccess vendored Normal file
View File

@ -0,0 +1,3 @@
Order deny,allow
Deny from all
Allow from 127.0.0.1

View File

@ -6,7 +6,8 @@
],
"settings": {
"cSpell.words": [
"benutzer"
"benutzer",
"khofmann"
]
}
}