symftony/identifier

A simple library to generate simple or complex identifier.

dev-master 2018-06-25 20:20 UTC

This package is not auto-updated.

Last update: 2024-11-10 06:17:51 UTC


README

A simple library to generate simple or complex identifier.

Installation

The recommended way to install Identifier is through Composer.

# Install Composer
curl -sS https://getcomposer.org/installer | php
php composer require symftony/identifier

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

Documentation

This library provide:

  • a lot of simple identifiers
  • a composite identifier
  • many formatter

Identifiers

Formatters

Usage

If you want to identify the machine with the sapi and phpversion and a uniqID

<?php
use Symftony\Identifier\Formatter\VsprintfFormatter;
use Symftony\Identifier\Formatter\StrReplaceFormatter;
use Symftony\Identifier\CompositeIdentifier;
use Symftony\Identifier\HostByNameIdentifier;
use Symftony\Identifier\PHPSapiNameIdentifier;
use Symftony\Identifier\PHPVersionIdentifier;
use Symftony\Identifier\UniqidIdentifier;

$identifier = new CompositeIdentifier(
    new HostByNameIdentifier(),
    new PHPSapiNameIdentifier(),
    new PHPVersionIdentifier(),
    new UniqidIdentifier()
);
// create a format
$format1 = new VsprintfFormatter('%s@%s(php-%s)#%s');
$format2 = new StrReplaceFormatter('{host_by_name}@{php_sapi_name}(php-{php_version})#{uniqid}');

// CompositeIdentifier use ImplodeFormatter by default
echo $identifier;// 192.168.1.12_cli_7.2.5_5b2779e6098ca
echo $identifier->getIdentifier();// 192.168.1.12_cli_7.2.5_5b2779e6098ca
echo $identifier->getIdentifier($format1);// 192.168.1.12@cli(php-7.2.5)#5b2779e6098ca
echo $identifier->getIdentifier($format2);// 192.168.1.12@cli(php-7.2.5)#5b2779e6098ca

Todo

Identifier builder/factory in order to easily create composite identifier with default format. See how to regenerate the identifier that can changed (time/unique ...)