A simple library to generate simple or complex identifier.
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';
This library provide:
- a lot of simple identifiers
- a composite identifier
- many formatter
- Machine identifiers
- HostByNameIdentifier (base on gethostbyname)
- HostnameIdentifier (base on gethostname)
- MyPidIdentifier (base on getmypid)
- PHPOSIdentifier (base on PHP_OS)
- PHPUnameIdentifier (base on php_uname)
- Configuration identifiers
- PHPSapiNameIdentifier (base on php_sapi_name)
- PHPVersionIdentifier (base on php_version)
- PHPVersionIdIdentifier (base on PHP_VERSION_ID)
- Filesystem identifiers
- MyGidIdentifier (base on getmygid)
- MyUidIdentifier (base on getmyuid)
- Unique identifiers
- SecureRandomStringIdentifier
- TimeIdentifier (base on time)
- UniqidIdentifier (base on uniqid)
- Uuid1Identifier (base on ramsey/uuid V1)
- Uuid3Identifier (base on ramsey/uuid V3)
- Uuid4Identifier (base on ramsey/uuid V4)
- Uuid5Identifier (base on ramsey/uuid V5)
- other
- StringIdentifier (inject your own string as identifier)
- CompositeIdentifier (compose with other identifiers)
- ImplodeFormatter (base on implode)
- StrReplaceFormatter (base on str_replace)
- VsprintfFormatter (base on vsprintf)
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
Identifier builder/factory in order to easily create composite identifier with default format. See how to regenerate the identifier that can changed (time/unique ...)