germania-kg/uuidserviceprovider

1.2.2 2022-05-30 13:38 UTC

README

Pimple Service Provider for working with Ben Ramsey's ramsey/uuid package

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status

Installation with Composer

$ composer require germania-kg/uuidserviceprovider

Setup

<?php
use Germania\UuidServiceProvider\UuidServiceProvider;

// A. Use with Slim or Pimple
$app = new \Slim\App;
$dic = $app->getContainer();
$dic = new Pimple\Container;

// B. Register Service Provider.
$dic->register( new UuidServiceProvider  );

Services

UUID.new

Factory: Returns a new version 4 (random) UUID object as Ramsey\Uuid\Uuid instance.

<?php
$uuid4 = $dic['UUID.new'];

UUID.new.hex

Returns the hex string representation of a UUID.new object.

<?php
$uuid4_hex = $dic['UUID.new.hex'];

UUID.Factory

Returns a callable that returns UUID object as Ramsey\Uuid\Uuid instance.

<?php
$factory = $dic['UUID.Factory'];
$uuid4 = $factory();

UUID.HexFactory

Returns a callable that returns the hex string representation of a UUID.new object.

<?php
$factory = $dic['UUID.HexFactory'];
$uuid4_hex = $factory();

Development

$ git clone https://github.com/GermaniaKG/UuidServiceProvider.git
$ cd UuidServiceProvider
$ composer install

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:

$ composer test
# or
$ vendor/bin/phpunit