Ratings | | Unique User Downloads | | Download Rankings |
Not yet rated by the users | | Total: 54 | | All time: 10,612 This week: 524 |
|
Description | | Author |
This package can maintain repositories of unique numbers via an API.
It provides a REST API that can be accessed to perform several types of operations to maintain one or more repositories that store unique numbers. Currently it can:
- Create, list and delete distinct repositories of unique numbers
- Stores a unique number in a given repository
- Get a list of all unique numbers in a repository
- Store a unique number in a given repository
The package also provides client code to access the repositories REST API. Innovation Award
July 2019
Number 10 |
Many applications need to use numbers to identify records of information that is stored in their databases. Those identifiers cannot have repeated values. Therefore the numbers must be unique.
It is also useful that the unique numbers are also random, so they cannot be easily predicted in a way that people with bad intentions can exploit the fact that they can anticipate future unique numbers generated by an application.
To make sure that a unique number is also randomly generated, it is necessary to verify if the number was already generated by the application, it is necessary to keep track of all numbers generated in the past.
This package provides an API for a service of repositories that keeps track of all unique numbers generated so far, thus making it easier to check available unique numbers from different parts of an application.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 12x
Winner: 1x |
|
Example
<?php
/**
* @author stev leibelt <artodeto@bazzline.net>
* @since 2015-09-12
*/
require_once __DIR__ . '/../vendor/autoload.php';
use Net\Bazzline\Component\Cli\Arguments\Arguments;
use Net\Bazzline\Component\CommandCollection\Http\Curl;
//begin of dependencies
$arguments = new Arguments($argv);
$baseUrl = '/unique-number-repository';
$command = new Curl();
$filePath = __DIR__ . '/../configuration/client.local.php';
$token = '';
$values = $arguments->getValues();
if (file_exists($filePath)) {
require_once $filePath;
}
//end of dependencies
//begin of configuration
$command->addHeader('Authorization: ' . $token);
$command->isJson();
$command->beSilent();
$command->noSslSecurity();
//end of configuration
/**
* @param callable $callable
* @param string $usage
*/
function execute($callable, $usage) {
try {
call_user_func($callable);
} catch (Exception $exception) {
echo 'An error occurred' . PHP_EOL;
echo $exception->getMessage() . PHP_EOL;
echo PHP_EOL;
echo $usage;
exit(1);
}
}
/**
* @param array $array
* @return array
*/
function extractValues(array $array)
{
return array_values($array);
}
/**
* @param array $values
* @param int $expectedNumberOfValues
*/
function throwExceptionIfInvalidNumberOfValuesWasProvided($values, $expectedNumberOfValues)
{
$numberOfValues = count($values);
$invalidNumberOfValuesProvided = ($numberOfValues !== $expectedNumberOfValues);
if ($invalidNumberOfValuesProvided) {
$message = 'invalid number of arguments supplied';
throw new RuntimeException($message);
}
}
/**
* @param string $value
* @param string $name
*/
function throwExceptionIfValueIsInvalid($value, $name)
{
$invalidValueProvided = (strlen($value) < 1);
if ($invalidValueProvided) {
$message = 'invalid ' . $name . ' supplied';
throw new RuntimeException($message);
}
}
|
Details
Unique Number Repository Webservice
Sometimes, you simple need to make sure you can fetch a unique number for a given problem scope.
To easy things up, this project will create a rest based webservice as backend and a command line frontend to support you solving this problem.
-
endpoint s
* "/unique-number-repository"
* DELETE: deleted a repository and all its unique numbers
* GET: returns list of all repository names
* PUT: creates a new repository
* "/unique-number-repository/{name}"
* DELETE: deletes a number from this repository
* GET: returns list of all numbers from this repository
* PUT: creates a new number for this repository
Install
By Hand
mkdir -p vendor/net_bazzline/unique_number_repository
cd vendor/net_bazzline/unique_number_repository
git clone https://github.com/bazzline/unique_number_repository .
composer require net_bazzline/unique_number_repository:dev-master
Configure
By Hand
cd <project root>/configuration
cp client.local.php.dist client.local.php
#adapt client.local.php
cp server.local.php.dist server.local.php
#adapt server.local.php
cd <project root>
./configuration/setup
Benefits
-
implement token authentication (you can and should override the existing token by creating your own client.local.php and server.local.php in configuration)
API
API is available at bazzline.net.
Thanks
History
-
upcomming
* @todo
* multiple storage (databases) are supported (right now, file storage is supported)
* return the right status code (403 instead of 404) if a user tries to delete a number he does not own
-
0.13.0 - released at 06.03.2016
* moved to psr-4 autoloading
-
0.12.3 - released at 18.12.2015
* updated dependency
-
0.12.2 - released at 19.11.2015
* updated dependency
-
0.12.1 - released at 18.11.2015
* updated dependency
-
0.12.0 - released at 30.09.2015
* changed "not authorized" http status code from wrong 403 to right 401
* introduced right usage of 403
-
0.11.0 - released at 20.09.2015
* added restriction that only the creator (repository or number) can delete the resource
-
0.10.4 - released at 16.09.2015
* fixed issue in authorization request
* made https an optional requirement
* updated README.md
* updated dependency
-
0.10.3 - released at 14.09.2015
addedAPI* section
* updated dependencies
-
0.10.2 - released at 13.09.2015
addedsetup* script to easy up after installation configuration
-
0.10.1 - released at 13.09.2015
* fixed authentication problem
-
0.10.0 - released at 13.09.2015
* downgraded to silex 1.2 to support php 5.3.3
* fixed broken links
* increased compatibility by using '/usr/bin/env' for client code
* removed unused dependencie
-
0.9.0 - released at 12.09.2015
* silix based server/backend
Final Words
Star it if you like it :-). Add issues if you need it. Pull patches if you enjoy it. Write a blog entry if you use it. Donate something if you love it :-].
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.