naffiq / php-randomorg-draws
PHP Random.org draws
Installs: 4 851
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/naffiq/php-randomorg-draws
Requires
Requires (Dev)
- codeclimate/php-test-reporter: ^0.4.4
- phpunit/phpunit: ^5.7
- vlucas/phpdotenv: ^2.4
This package is auto-updated.
Last update: 2025-10-23 03:59:46 UTC
README
This library helps you with connecting your app to Random.org's Third-Party Draws service.
Installation
Preferable way to install this package is through composer:
$ composer require naffiq/php-randomorg-draws
Usage
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.
<?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.
<?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
Handling API errors
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.
Contributing and testing
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:
RANDOMORG_LOGIN=your_random_org_login RANDOMORG_PASSWORD=your_random_org_password
And run
$ phpunit