symftony / identifier
A simple library to generate simple or complex identifier.
dev-master
2018-06-25 20:20 UTC
Requires
- php: >=5.6
Requires (Dev)
- phpunit/phpunit: ^5.7
- ramsey/uuid: ^3.7
Suggests
- ramsey/uuid: Provide RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID).
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
- 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)
Formatters
- ImplodeFormatter (base on implode)
- StrReplaceFormatter (base on str_replace)
- VsprintfFormatter (base on vsprintf)
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 ...)