<commit_before><?php
# API Sample: GET http://your-site.com/api/updated

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

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

$app = new \Slim\App(["settings" => $config]);

# Logging Support
$container['logger'] = function($c) {
    $logger = new \Monolog\Logger('my_logger');
    $file_handler = new \Monolog\Handler\StreamHandler("../logs/app.log");
    $logger->pushHandler($file_handler);
    return $logger;
};

# Access database
$container['db'] = function ($c) {
    $db = $c['settings']['db'];
    $pdo = new PDO("mysql:host=" . $db['host'] . ";dbname=" . $db['dbname'],
        $db['user'], $db['pass']);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    return $pdo;
};

# TESTFLIGHT: http://localhost:8080/api.php/api/mirror/{name}
$app->get('/api/mirror/{name}', function (Request $request, Response $response) {
    $name = $request->getAttribute('name');
    $response->getBody()->write("Hello, $name");

    return $response;
});

# Provision: Database API Connection

# Get All Titles on site: Database Macro Search
$app->get('/api/titles', function(Request $request, Response $response){
    $sql = "SELECT * FROM siren_titles_list";
    try{
        // Get DB Object
        $db = new db();
        // Connect
        $db = $db->connect();
        $stmt = $db->query($sql);
        $titled = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo json_encode($titles);
    } catch(PDOException $e){
        echo '{"error": {"text": '.$e->getMessage().'}';
    }
});
/*<commit_msg>Updated API to latest version (function in-progress)<commit_after><?php
# API Sample: GET http://your-site.com/api/updated

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

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

$app = new \Slim\App(["settings" => $config]);

# Logging Support
$container['logger'] = function($c) {
    $logger = new \Monolog\Logger('my_logger');
    $file_handler = new \Monolog\Handler\StreamHandler("../logs/app.log");
    $logger->pushHandler($file_handler);
    return $logger;
};

# Access database
$container['db'] = function ($c) {
    $db = $c['settings']['db'];
    $pdo = new PDO("mysql:host=" . $db['host'] . ";dbname=" . $db['dbname'],
        $db['user'], $db['pass']);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    return $pdo;
};

# TESTFLIGHT: http://localhost:8080/api.php/api/mirror/{name}
$app->get('/api/mirror/{name}', function (Request $request, Response $response) {
    $name = $request->getAttribute('name');
    $response->getBody()->write("Hello, $name");

    return $response;
});

# Provision: Database API Connection

# Get All Titles on site: Database Macro Search
$app->get('/api/titles', function(Request $request, Response $response){
    $sql = "SELECT * FROM siren.siren_titles_list";
    try{
        // Get DB Object
        $db = new db();
        // Connect
        $db = $db->connect();
        $stmt = $db->query($sql);
        $titles = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo json_encode($titles);
    } catch(PDOException $e){
        echo '{"error": {"text": '.$e->getMessage().'}';
    }
});
/*
{'fraction_non_alphanumeric': 0.2029151186053158, 'fraction_numerical': 0.002286367533581023, 'mean_word_length': 3.5751633986928106, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6230153', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1170, 'n_words': 234}