tackacoder / tournament-services
Generate different tournaments with teams and schedule.
v1.2.2
2023-06-15 11:59 UTC
Requires
- php: >=8.1
- nesbot/carbon: ^2.66
- symfony/property-access: ^6.2
- symfony/serializer: ^6.2
- symfony/yaml: ^6.2
Requires (Dev)
- pestphp/pest: ^2.6
- phpstan/phpstan: ^1.10
- rector/rector: ^0.16.0
- symfony/var-dumper: ^6.2
README
Features
- Create a simple round robin tournament with an even count teams and home/away matches
Installation
$ composer require tackacoder/tournament-services
Basic Usage
require './vendor/autoload.php'; use Carbon\CarbonImmutable; use Tackacoder\Tournament\Tournament; /** * Create a tournament * * ` Tournament * - Tournament name * - Tournament Mode * - Tournament generate date * * ` Teams * - List of teams * * ` Matches * - Day name * * ` Schedules * - Schedule Date * * ` Matches * - Home Team * - Away Team * - Score * - Stats * * TOURNAMENT_MODE is a service variable * By default, services are included : * - championship * - cup */ $TOURNAMENT_MODE = 'championship'; $tournament = new Tournament('My tournament title', $TOURNAMENT_MODE); // OR $tournament = new Tournament(); $tournament->setName('My tournament title')->setMode($TOURNAMENT_MODE); // Complete with teams $tournament->setTeams([ [ "name" => "Team One", "status" => true ], [ "name" => "Team Two", "status" => false ], [ "name" => "Team Three", "status" => true ], [ "name" => "Team Four", "status" => true ] ]); // Change the start date $tournament->setDate(date: CarbonImmutable::now('UTC')); $tournament->addService(new ChampionshipService()); $result = $tournament->generate();
Championship Service Usage
The Championship Service object can be construct with optionals parameters :
- interval : See documentation
- callable : Closure to send event on diffrent endpoint
new ChampionshipService('2 days', function ($args) { $endpoint = $args['name']; event(new Event($args)); });
On generate method, yon can add some configuration parameters to send to Services. For ChampionshipService
, you can add mirror and shift configuration.
[...] $tournament->generate([ 'mirror' => false, // false => each Teams meet once, true => home & away matches 'shift' => 3 // Shift as many matches to avoid meeting teams on the same model ]);
The default configuration parameters to generate()
are :
* The name of the tournament
* The date of creation
* Teams collection
Create a generator service
use Tackacoder\Tournament\Services\Service; use Tackacoder\Tournament\Supports\ServiceInterface; class MyServiceService extends Service implements ServiceInterface { /** * NEEDED to find the generator */ protected string $name = 'my_service'; public function generate(array $config): array { $this->setConfig($config); $date = $this->getConfig('date'); $teams = $this->getConfig('teams'); $name = $this->getConfig('name'); return []; } } // In other file $tournament = new Tournament(); $tournament->setMode('my_service');
Contributing
Run Functional Tests
$ composer test
or $ php vendor/bin/pest