<?php

use App\Honeypot\Honeypot;
$context = Timber::get_context();
$honeyPot = new Honeypot();
$context['honeypotHtml'] = $honeyPot->generate('hp_field', 'hp_time');
Timber::render('pages/contact.twig', $context);
use App\Form\SimpleContact\Processor;
use App\Honeypot\Honeypot;
require $_SERVER['DOCUMENT_ROOT'] . '/app/bootstrap.php';
// Request responder
$respond = function ($response, $status_code = 200, $status_message = 'OK') {
    header($_SERVER['SERVER_PROTOCOL'] . " {$status_code} {$status_message}");
    header('Content-type: application/json');
    echo json_encode($response);
    exit;
};
try {
    // Get our input via standard form or JSON body
    $input = !empty($_POST) ? $_POST : json_decode(file_get_contents('php://input'), true);
    // Validate the honeypot fields before processing the form input.
    // No need to process anything if this is a possible "attack".
    $honeyPot = new Honeypot();
    if (!$honeyPot->validate(array('honeyPot' => $_POST['hp_field'], 'honeyPotTime' => $_POST['hp_time']))) {
        $respond(array('success' => false), 403);
    }
    // The processor will handle all the details of the submission (input normalizing,
    // validation, mailing, API submission, etc)
    $processor = new Processor($input);
    // Submit the form. The processor will throw an exception if anything doesn't
    // validate or work correctly, so we don't need to check if it was actually
    // successful.
    $processor->process();
    $respond(array('success' => true), 200);
} catch (ProcessorValidationException $exception) {
    $respond(array('success' => false, 'messages' => (array) $processor->getMessages()), 422, 'Invalid request');
} catch (Exception $exception) {
    //ddd($exception);