Rename Game and Bootsrap methods to address feedback
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ use Doctrine\ORM\Tools\SchemaTool;
|
||||
|
||||
class Bootstrap
|
||||
{
|
||||
public static function game(): Game
|
||||
public static function createGame(): Game
|
||||
{
|
||||
$pdo = new \PDO($GLOBALS['DB_DSN'], $GLOBALS["DB_USER"], $GLOBALS["DB_PASSWORD"]);
|
||||
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ class Game
|
||||
* Returns the game's entity manager.
|
||||
* @return EntityManagerInterface The game's database entity manager.
|
||||
*/
|
||||
public function db(): EntityManagerInterface
|
||||
public function getEntityManager(): EntityManagerInterface
|
||||
{
|
||||
return $this->entityManager;
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class Game
|
||||
* Returns the game's event manager.
|
||||
* @return EventManager The game's event manager.
|
||||
*/
|
||||
public function events(): EventManager
|
||||
public function getEventManager(): EventManager
|
||||
{
|
||||
return $this->eventManager;
|
||||
}
|
||||
|
||||
@@ -63,13 +63,13 @@ class ModuleManager
|
||||
*/
|
||||
public static function register(Game $g, string $library, PackageInterface $package)
|
||||
{
|
||||
$m = $g->db()->getRepository(Module::class)->find($library);
|
||||
$m = $g->getEntityManager()->getRepository(Module::class)->find($library);
|
||||
if ($m) {
|
||||
throw new ModuleAlreadyExistsException($library);
|
||||
} else {
|
||||
// TODO: handle error cases here.
|
||||
$m = new Module($library);
|
||||
$m->save($g->db());
|
||||
$m->save($g->getEntityManager());
|
||||
|
||||
// Subscribe to the module's events.
|
||||
$subscriptions = ModuleManager::getPackageSubscriptions($package);
|
||||
@@ -77,7 +77,7 @@ class ModuleManager
|
||||
$pattern = $s['pattern'];
|
||||
$class = $s['class'];
|
||||
|
||||
$g->events()->subscribe($pattern, $class);
|
||||
$g->getEventManager()->subscribe($pattern, $class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,12 +93,12 @@ class ModuleManager
|
||||
*/
|
||||
public static function unregister(Game $g, string $library, PackageInterface $package)
|
||||
{
|
||||
$m = $g->db()->getRepository(Module::class)->find($library);
|
||||
$m = $g->getEntityManager()->getRepository(Module::class)->find($library);
|
||||
if (!$m) {
|
||||
throw new ModuleDoesNotExistException($library);
|
||||
} else {
|
||||
// TODO: handle error cases here.
|
||||
$m->delete($g->db());
|
||||
$m->delete($g->getEntityManager());
|
||||
|
||||
// Unsubscribe the module's events.
|
||||
$subscriptions = ModuleManager::getPackageSubscriptions($package);
|
||||
@@ -107,7 +107,7 @@ class ModuleManager
|
||||
$class = $s['class'];
|
||||
|
||||
try {
|
||||
$g->events()->unsubscribe($pattern, $class);
|
||||
$g->getEventManager()->unsubscribe($pattern, $class);
|
||||
} catch (SubscriptionNotFoundException $e) {
|
||||
// TODO: log this but continue on.
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ class BootstrapTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGame()
|
||||
{
|
||||
$g = Bootstrap::game();
|
||||
$this->assertNotNull($g->db());
|
||||
$this->assertNotNull($g->events());
|
||||
$g = Bootstrap::createGame();
|
||||
$this->assertNotNull($g->getEntityManager());
|
||||
$this->assertNotNull($g->getEventManager());
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -33,7 +33,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$game->method('db')->willReturn($this->getEntityManager());
|
||||
$game->method('getEntityManager')->willReturn($this->getEntityManager());
|
||||
|
||||
$package = $this->getMockBuilder(PackageInterface::class)->getMock();
|
||||
|
||||
@@ -62,7 +62,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$game->method('db')->willReturn($this->getEntityManager());
|
||||
$game->method('getEntityManager')->willReturn($this->getEntityManager());
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
@@ -84,8 +84,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$game->method('db')->willReturn($this->getEntityManager());
|
||||
$game->method('events')->willReturn($eventManager);
|
||||
$game->method('getEntityManager')->willReturn($this->getEntityManager());
|
||||
$game->method('getEventManager')->willReturn($eventManager);
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
@@ -129,8 +129,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$game->method('db')->willReturn($this->getEntityManager());
|
||||
$game->method('events')->willReturn($eventManager);
|
||||
$game->method('getEntityManager')->willReturn($this->getEntityManager());
|
||||
$game->method('getEventManager')->willReturn($eventManager);
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
@@ -173,8 +173,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$game->method('db')->willReturn($this->getEntityManager());
|
||||
$game->method('events')->willReturn($eventManager);
|
||||
$game->method('getEntityManager')->willReturn($this->getEntityManager());
|
||||
$game->method('getEventManager')->willReturn($eventManager);
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
@@ -198,8 +198,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$game->method('db')->willReturn($this->getEntityManager());
|
||||
$game->method('events')->willReturn($eventManager);
|
||||
$game->method('getEntityManager')->willReturn($this->getEntityManager());
|
||||
$game->method('getEventManager')->willReturn($eventManager);
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
@@ -248,8 +248,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$game->method('db')->willReturn($this->getEntityManager());
|
||||
$game->method('events')->willReturn($eventManager);
|
||||
$game->method('getEntityManager')->willReturn($this->getEntityManager());
|
||||
$game->method('getEventManager')->willReturn($eventManager);
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
@@ -297,8 +297,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$game->method('db')->willReturn($this->getEntityManager());
|
||||
$game->method('events')->willReturn($eventManager);
|
||||
$game->method('getEntityManager')->willReturn($this->getEntityManager());
|
||||
$game->method('getEventManager')->willReturn($eventManager);
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user