1st commit
This commit is contained in:
66
index.php
Normal file
66
index.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
ini_set("display_errors", 1);
|
||||
error_reporting(-1);
|
||||
|
||||
const ROOT_PATH = __DIR__;
|
||||
|
||||
const BASE_URL = "http://php-task1";
|
||||
|
||||
include __DIR__ . '/vendor/autoload.php';
|
||||
include __DIR__ . '/bootstrap/db.php';
|
||||
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
use Illuminate\Database\Eloquent;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use ps\app\Models\Posts;
|
||||
|
||||
|
||||
|
||||
function processInput($uri){
|
||||
$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
function processOutput($response){
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
// function getPDOInstance(){
|
||||
// return new PDO('mysql:host=localhost;dbname=booksapi;charset=utf8', 'root', '');
|
||||
// }
|
||||
|
||||
$router = new RouteCollector();
|
||||
|
||||
$router->get('/', function(){
|
||||
return 'Like at Home!';
|
||||
});
|
||||
|
||||
$router->get('posts', function(){
|
||||
echo Posts::all();
|
||||
});
|
||||
|
||||
$router->get('login', [\ps\app\Controllers\LoginController::class, 'actionGetLoginForm']);
|
||||
|
||||
$dispatcher = new Dispatcher($router->getData());
|
||||
|
||||
try {
|
||||
|
||||
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], processInput($_SERVER['REQUEST_URI']));
|
||||
|
||||
} catch (Phroute\Exception\HttpRouteNotFoundException $e) {
|
||||
|
||||
var_dump($e);
|
||||
die();
|
||||
|
||||
} catch (Phroute\Exception\HttpMethodNotAllowedException $e) {
|
||||
|
||||
var_dump($e);
|
||||
die();
|
||||
|
||||
}
|
||||
|
||||
processOutput($response);
|
||||
|
Reference in New Issue
Block a user