PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Mateo   PHP Banking System API   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Banking System API
API to implement banking transactions
Author: By
Last change:
Date: 6 months ago
Size: 765 bytes
 

Contents

Class file image Download
<?php

use BankApi\Db\Sql;
use
BankApi\Routes;
use
Mateodioev\HttpRouter\Router;
use
BankApi\Models\Error as ErrorResponse;
use
Mateodioev\HttpRouter\exceptions\{HttpNotFoundException, RequestException};

require
__DIR__ . '/vendor/autoload.php';

Sql::prepare(__DIR__);
$router = new Router;

Routes::register($router);

try {
   
$router->run();
} catch (
HttpNotFoundException $e) {
   
$router->send(ErrorResponse::json($e->getMessage() ?? 'Not found', $e->getCode() ?: 404));
} catch (
RequestException $e) {
   
$router->send(ErrorResponse::json($e->getMessage() ?? 'Server error', $e->getCode() ?: 500));
} catch (
Exception $e) {
   
$router->send(ErrorResponse::json('Unknown error', 500));
   
// $router->send(ErrorResponse::json($e->getMessage(), 500));
}