Initial Commit
This commit is contained in:
commit
ddf09fe00c
113 changed files with 187148 additions and 0 deletions
55
app/Providers/GameServiceProvider.php
Normal file
55
app/Providers/GameServiceProvider.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Game\GameBuilder;
|
||||
use App\Game\GameBoardState;
|
||||
use App\Game\GameService;
|
||||
use App\Game\GameSession;
|
||||
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Contracts\Support\DeferrableProvider;
|
||||
|
||||
class GameServiceProvider extends ServiceProvider implements DeferrableProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(GameBoardState::class, function($app) {
|
||||
$width = (int) config('app.game.board.width', 4);
|
||||
$height = (int) config('app.game.board.height', 4);
|
||||
return new GameBoardState($width, $height);
|
||||
});
|
||||
|
||||
$this->app->singleton(GameService::class, function ($app) {
|
||||
// Try loading from session.
|
||||
$session_key = config('app.game.session_name', 'game.service');
|
||||
$service = Session::get($session_key);
|
||||
|
||||
// No service in session, create a new one and store it.
|
||||
if (!$service) {
|
||||
$game_session = $app->make(GameSession::class);
|
||||
$service = new GameService($game_session);
|
||||
Session::put($session_key, $service);
|
||||
}
|
||||
return $service;
|
||||
});
|
||||
|
||||
$this->app->alias(GameService::class, 'game');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return [ 'game', GameService::class, GameBoardState::class ];
|
||||
}
|
||||
}
|
||||
Reference in a new issue