Add Bootstrap as (at least temporary) way to construct a game.

This commit is contained in:
Austen McDonald
2016-05-15 14:50:30 -07:00
parent 5cce8f5a69
commit c60794511f
2 changed files with 53 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace LotGD\Core;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\AnsiQuoteStrategy;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\Tools\SchemaTool;
class Bootstrap
{
public static function game(): Game
{
$pdo = new \PDO($GLOBALS['DB_DSN'], $GLOBALS["DB_USER"], $GLOBALS["DB_PASSWORD"]);
// Read db annotations from model files
$configuration = Setup::createAnnotationMetadataConfiguration(["src/Models"], true);
$configuration->setQuoteStrategy(new AnsiQuoteStrategy());
$configuration->addFilter("soft-deleteable", 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter');
$entityManager = EntityManager::create(["pdo" => $pdo], $configuration);
$entityManager->getFilters()->enable("soft-deleteable");
$entityManager->getEventManager()->addEventSubscriber(new \Gedmo\SoftDeleteable\SoftDeleteableListener());
// Create Schema
$metaData = $entityManager->getMetadataFactory()->getAllMetadata();
$schemaTool = new SchemaTool($entityManager);
$schemaTool->updateSchema($metaData);
$eventManager = new EventManager($entityManager);
return new Game($entityManager, $eventManager);
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Tests;
use LotGD\Core\Bootstrap;
class BootstrapTest extends \PHPUnit_Framework_TestCase
{
public function testGame()
{
$g = Bootstrap::game();
$this->assertNotNull($g->db());
$this->assertNotNull($g->events());
}
}