Wallogit.com
2017 © Pedro Peláez
PHP Random.org draws
This library helps you with connecting your app to Random.org's Third-Party Draws service., (*2)
Preferable way to install this package is through composer:, (*3)
$ composer require naffiq/php-randomorg-draws
You have to register random.org account and provide login/password to \naffiq\randomorg\DrawService
constructor. Then you can create draws via \naffiq\randomorg\DrawService::newDraw() method, which
will spawn an object of \naffiq\randomprg\Draw., (*4)
<?php
$service = new \naffiq\randomorg\DrawService('random.org_login', 'random.org_password');
$draw = $service->newDraw(
'Title', // Name of the draw
1, // ID of created draw, which will be passed to random.org
['user_1@email.com', 'user_2@email.com'], // You can provide any unique identifiers of your participants
1, // Winners count
'test' // Use 'private' or 'public' in production
);
$draw->pushEntry('user_3@email.com'); // Adds new entry
To start draw run \naffiq\randomorg\DrawService::holdDraw() method with created $draw. In result
you will get instance of \naffiq\randomorg\DrawResponse class., (*5)
<?php /** * @var $service \naffiq\randomorg\DrawService * @var $draw \naffiq\randomorg\Draw */ $response = $service->holdDraw($draw); var_dump($response->getWinners()); // Will output all winners of created draw
Any error, that was generated by Random.org API is thrown as an instance of \naffiq\randomorg\DrawException.
It passes error code and message as well as additional data, which is accessible via
\naffiq\randomorg\DrawException::getData() method., (*6)
Any contribution is highly welcomed. If you want to run tests provide RANDOMORG_LOGIN and
RANDOMORG_PASSWORD environment variables. They can be automatically initialized them from .env file.
Just specify them as follows:
```.env
RANDOMORG_LOGIN=your_random_org_login
RANDOMORG_PASSWORD=your_random_org_password, (*7)
And run ```bash $ phpunit