PHP Classes

File: tests/quick_login.php

Recommend this page to a friend!
  Packages of Adrian M   PHP CRUD API Generator   tests/quick_login.php   Download  
File: tests/quick_login.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP CRUD API Generator
Create an API to access MySQL database record
Author: By
Last change: up
Date: 3 months ago
Size: 683 bytes
 

Contents

Class file image Download
<?php
require_once __DIR__ . '/../vendor/autoload.php';

use
App\Database\Database;
use
App\Application\Router;
use
App\Auth\Authenticator;

// Simulate POST request with form data
$_GET = ['action' => 'login'];
$_POST = ['username' => 'admin', 'password' => 'secret'];
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';

$dbConfig = require __DIR__ . '/../config/db.php';
$apiConfig = require __DIR__ . '/../config/api.php';

$db = new Database($dbConfig);
$auth = new Authenticator($apiConfig, $db->getPdo());
$router = new Router($db, $auth);

ob_start();
$router->route($_GET);
$response = ob_get_clean() ?: '';

echo
$response;