2017 © Pedro Peláez
 

library keys

Validatable key objects.

image

brightnucleus/keys

Validatable key objects.

  • Wednesday, July 5, 2017
  • by schlessera
  • Repository
  • 2 Watchers
  • 2 Stars
  • 48 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 20 % Grown

The README.md

Bright Nucleus Keys

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

This package provides validatable key objects that are meant to be used as identifiers., (*2)

Table Of Contents

Installation

The best way to use this package is through Composer:, (*3)

composer require brightnucleus/keys

Basic Usage

Basic Key class

Usage of the basic BrightNucleus\Keys\Key class is very simple, you just instantiate it by passing the actual value you want to use as a key through the constructor., (*4)

Example:, (*5)

<?php namespace Vendor\Package;

use BrightNucleus\Keys\Key;

$key = new Key('my_option');
echo $key;
// Output: 'my_option'

UUID class

An UUID is a "Universally Unique IDentifier"., (*6)

To use the BrightNucleus\Keys\UUID class, you should instantiate it through one of the named constructors:, (*7)

  • UUID::uuid1(): Generate a version 1 (time-based) UUID object.
  • UUID::uuid3($namespace, $name): Generate a version 3 (name-based and hashed with MD5) UUID object.
  • UUID::uuid4(): Generate a version 4 (random) UUID object.
  • UUID::uuid5($namespace, $name): Generate a version 5 (name-based and hashed with SHA1) UUID object.

Example:, (*8)

<?php namespace Vendor\Package;

use BrightNucleus\Keys\UUID;

$randomUUID = UUID::uuid4();
echo $randomUUID;
// Output: random UUID, in a format similar to '123e4567-e89b-12d3-a456-426655440000'

$hashedUUID = UUID::uuid5(UUID::NAMESPACE_URL, 'https://www.brightnucleus.com');
echo $hashedUUID;
// Output: '63ab6383-0ad4-559a-b16b-afcec9cc77e9'

Advanced Usage

You can extend the BrightNucleus\Keys\Key class to provide your own unique scheme for providing identifiers. Ensure that both the validation as well as the serialization features work as intended for your custom implementation., (*9)

Example:, (*10)

<?php namespace Vendor\Package;

use BrightNucleus\Keys\Key;

class TimestampedKey extends Key
{

    /**
     * Initialize a new TimestampedKey object.
     */
    public function __construct()
    {
        $dateTime = new \DateTimeImmutable();
        $this->data = $dateTime->getTimestamp();
    }
}

$key = new TimestampedKey();
echo $key;
// Output: Unix timestamp value in the format '1499248161';

Contributing

All feedback / bug reports / pull requests are welcome., (*11)

License

Copyright (c) 2017 Alain Schlesser, Bright Nucleus, (*12)

This code is licensed under the MIT License., (*13)

The Versions

05/07 2017

dev-master

9999999-dev

Validatable key objects.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/07 2017

v0.1.2

0.1.2.0

Validatable key objects.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/07 2017

v0.1.1

0.1.1.0

Validatable key objects.

  Sources   Download

MIT

The Requires

 

The Development Requires

04/07 2017

v0.1.0

0.1.0.0

Validatable key objects.

  Sources   Download

MIT

The Requires

 

The Development Requires