PHP Classes

File: public/index.php

Recommend this page to a friend!
  Classes of uche   PHP Job Portal Project API   public/index.php   Download  
File: public/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Job Portal Project API
API to post working jobs and let freelancers apply
Author: By
Last change:
Date: 2 years ago
Size: 1,237 bytes
 

Contents

Class file image Download
<?php
if (PHP_SAPI == 'cli-server') {
   
// To help the built-in PHP dev server, check if the request was actually for
    // something which should probably be served as a static file
   
$url = parse_url($_SERVER['REQUEST_URI']);
   
$file = __DIR__ . $url['path'];
    if (
is_file($file)) {
        return
false;
    }
}

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

session_start();

// Instantiate the app
$settings = require __DIR__ . '/../src/settings.php';
$app = new \Slim\App($settings);
$container = $app->getContainer();
//setup env file
$dotenv = new \Dotenv\Dotenv(__DIR__ . '/..');
$dotenv->load();

// PDO database library
$container['db'] = function ($c) {
   
$settings = $c->get('settings')['db'];
   
$pdo = new PDO("mysql:host=" . $settings['host'] . ";dbname=" . $settings['dbname'],
       
$settings['user'], $settings['pass']);
   
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    return
$pdo;
};
// Set up dependencies
require __DIR__ . '/../src/dependencies.php';

// Register middleware
require __DIR__ . '/../src/middleware.php';

// Register routes
require __DIR__ . '/../src/routes.php';

// Run app
$app->run();