Created
April 28, 2017 00:40
-
-
Save msfidelis/7a9b2c4222f52c7de8236b8712356c14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require './vendor/autoload.php'; | |
use Doctrine\ORM\Tools\Setup; | |
use Doctrine\ORM\EntityManager; | |
use Psr7Middlewares\Middleware\TrailingSlash; | |
/** | |
* Configurações | |
*/ | |
$configs = [ | |
'settings' => [ | |
'displayErrorDetails' => true, | |
], | |
]; | |
/** | |
* Container Resources do Slim. | |
* Aqui dentro dele vamos carregar todas as dependências | |
* da nossa aplicação que vão ser consumidas durante a execução | |
* da nossa API | |
*/ | |
$container = new \Slim\Container($configs); | |
/** | |
* Converte os Exceptions entro da Aplicação em respostas JSON | |
*/ | |
$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(["message" => $exception->getMessage()], $statusCode); | |
}; | |
}; | |
$isDevMode = true; | |
/** | |
* Diretório de Entidades e Metadata do Doctrine | |
*/ | |
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src/Models/Entity"), $isDevMode); | |
/** | |
* Array de configurações da nossa conexão com o banco | |
*/ | |
$conn = array( | |
'driver' => 'pdo_sqlite', | |
'path' => __DIR__ . '/db.sqlite', | |
); | |
/** | |
* Instância do Entity Manager | |
*/ | |
$entityManager = EntityManager::create($conn, $config); | |
/** | |
* Coloca o Entity manager dentro do container com o nome de em (Entity Manager) | |
*/ | |
$container['em'] = $entityManager; | |
/** | |
* Application Instance | |
*/ | |
$app = new \Slim\App($container); | |
/** | |
* @Middleware Tratamento da / do Request | |
* true - Adiciona a / no final da URL | |
* false - Remove a / no final da URL | |
*/ | |
$app->add(new TrailingSlash(false)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment