PHP code example of tackacoder / tournament-services

1. Go to this page and download the library: Download tackacoder/tournament-services library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tackacoder / tournament-services example snippets




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    "status" => true
    ],
    [
        "name" => "Team Four",
        "status" => true
    ]
]);
// Change the start date
$tournament->setDate(date: CarbonImmutable::now('UTC'));

$tournament->addService(new ChampionshipService());
$result = $tournament->generate();

new ChampionshipService('2 days', function ($args) {
    $endpoint = $args['name'];
    event(new Event($args));
});


[...]

$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
]);

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');