<?php

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

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

$configs = [
    'settings' => [
        'displayErrorDetails' => false,
    ],
];

$container = new \Slim\Container($configs);

$container['errorHandler'] = function ($c) {
    return function ($request, $response, $exception) use ($c) {
        $statusCode = $exception->getCode() ? $exception->getCode() : 500;
        return $c['response']->withStatus($statusCode)
            ->withHeader('Content-Type', 'Application/json')
            ->withJson(["mensagem" => $exception->getMessage()], $statusCode);
    };
};

$paths = array(".App/Models/Entity");
$isDevMode = false;

$dbParams = array(
    'driver'   => 'pdo_mysql',
    'user'     => 'fourwardmysql@mysql4ward',
    'password' => '@kirede!18#@',
    'dbname'   => 'db_convicto',
    'host' => 'mysql4ward.mysql.database.azure.com',
);


$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);

$entityManager = EntityManager::create($dbParams, $config);

//var_dump($entityManager->getConnection()->errorInfo());

$container['em'] = $entityManager;

$app = new \Slim\App($container);
