Download the PHP package torugo/util without Composer
On this page you can find all versions of the php package torugo/util. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package util
PHP Utility library
Library with useful classes and methods.
Table of Contents
- Requirements
- Installation
- Utilities
- CDT (Compressed Date and Time)
- get
- fromTimestamp
- fromDateTime
- toMicrotime
- toDateTime
- DateWriter
- Format options
- Internationalization
- Usage
- SemVer
- TBase64 (url safe)
- TEncrypt
- Usage
- Cipher algorithm
- TFile
- Check if file exists
- Create a file
- Checking if a file is writable
- Load file lines
- Parsing .env files
- Parsing .json files
- Parsing .key files
- TPass
- Options
- Setting symbols source
- Checking password strength
- TUID (Torugo Unique ID)
- Generating
- Validating
- Getting Date and Time
- TRandom
- Random strings
- Parameters
- Random Numbers
- Random Numbers with leading zeros
- Traits
- Empty Values Trait
- From Array Factory
- Contribute
- License
Requirements
- PHP 8+
- PHP mbstring extension installed and loaded.
- PHP openssl extension installed and loaded.
- Composer 2+
Installation
On terminal type:
Or add to your require list on composer.json file:
Utilities
CDT (Compressed Date and Time)
CDT is a way of storing date and time including milliseconds.
get
Returns a CDT from current date/time.
fromTimestamp
Generates a CDT from a timestamp or microtime.
fromDateTime
Generates a CDT from a PHP DateTime object.
toMicrotime
Converts a CDT to a microtime (float) number.
toDateTime
Converts a CDT to a PHP DateTime object.
DateWriter
Transforms DateTime objects to written date/time.
Format options
Accepts all PHP DateTimeInterface::format
characters.
Everything in brackets ([]
) will not change in any way.
By default, all names of months and days of the week are defined as title case, to transform the cases use the markings:
*{ ... }
To convert to uppercase.%{ ... }
To convert to lowercase.
Internationalization
Languages available to write the names of months and days of the week.
Option | Language | Examples |
---|---|---|
'de' | Deutsch | "Januar" ... "Dezember" / "Montag" ... "Sonntag" |
'en' | English | "January" ... "December" / "sunday" ... "saturday" |
'es' | Spanish | "Enero" ... "Diciembre" / "Domingo" ... "Sábado" |
'fr' | French | "Janvier" ... "Décembre" / "Dimanche" ... "Samedi" |
'pt' | Portuguese | "Janeiro" ... "Dezembro" / "Domingo" ... "Sábado" |
Usage
SemVer
Validates and compare semantic version numbers. The version number must follow semver.org rules
Usage
TBase64 (url safe)
Encodes and decodes strings to Base64 that can be used on URLs.
Usage
TEncrypt
Encrypts/Decrypts strings using symmetric keys.
[!NOTE] Symmetric key:
Means that the key used for encryption must be the same for decryption.
Each cipher algorithm has a minimum key length in bytes, check the table bellow.
Usage
Cipher algorithm
Use the TCipher enum to set a new cipher algorithm.
Setting the cipher algorithm:
List of all supported cipher algorithms, default is AES_256_CFB
.
Algorithm | Min key length in bytes |
---|---|
AES_128_CBC | 16 |
AES_128_CFB | 16 |
AES_128_CFB1 | 16 |
AES_128_CFB8 | 16 |
AES_128_CTR | 16 |
AES_128_OFB | 16 |
AES_128_WRAP_PAD | 16 |
AES_192_CBC | 24 |
AES_192_CFB | 24 |
AES_192_CFB1 | 24 |
AES_192_CFB8 | 24 |
AES_192_CTR | 24 |
AES_192_OFB | 24 |
AES_192_WRAP_PAD | 24 |
AES_256_CBC | 32 |
AES_256_CFB | 32 |
AES_256_CFB1 | 32 |
AES_256_CFB8 | 32 |
AES_256_CTR | 32 |
AES_256_OFB | 32 |
AES_256_WRAP_PAD | 32 |
ARIA_128_CBC | 16 |
ARIA_128_CFB | 16 |
ARIA_128_CFB1 | 16 |
ARIA_128_CFB8 | 16 |
ARIA_128_CTR | 16 |
ARIA_128_OFB | 16 |
ARIA_192_CBC | 24 |
ARIA_192_CFB | 24 |
ARIA_192_CFB1 | 24 |
ARIA_192_CFB8 | 24 |
ARIA_192_CTR | 24 |
ARIA_192_OFB | 24 |
ARIA_256_CBC | 32 |
ARIA_256_CFB | 32 |
ARIA_256_CFB1 | 32 |
ARIA_256_CFB8 | 32 |
ARIA_256_CTR | 32 |
ARIA_256_OFB | 32 |
CAMELLIA_128_CBC | 16 |
CAMELLIA_128_CFB | 16 |
CAMELLIA_128_CFB1 | 16 |
CAMELLIA_128_CFB8 | 16 |
CAMELLIA_128_CTR | 16 |
CAMELLIA_128_OFB | 16 |
CAMELLIA_192_CBC | 24 |
CAMELLIA_192_CFB | 24 |
CAMELLIA_192_CFB1 | 24 |
CAMELLIA_192_CFB8 | 24 |
CAMELLIA_192_CTR | 24 |
CAMELLIA_192_OFB | 24 |
CAMELLIA_256_CBC | 32 |
CAMELLIA_256_CFB | 32 |
CAMELLIA_256_CFB1 | 32 |
CAMELLIA_256_CFB8 | 32 |
CAMELLIA_256_CTR | 32 |
CAMELLIA_256_OFB | 32 |
CHACHA20 | 32 |
DES_EDE_CBC | 16 |
DES_EDE_CFB | 16 |
DES_EDE3_CFB | 24 |
DES_EDE3_CFB1 | 24 |
DES_EDE3_CFB8 | 24 |
DES_EDE3_OFB | 24 |
SM4_CBC | 16 |
SM4_CFB | 16 |
SM4_CTR | 16 |
SM4_OFB | 16 |
TFile
Manipulates text files parsing its content.
Check if file exists
The static method exists
returns if a file exists in a given path,
you can use the argument createIfNotExists
to create a file if it not exist.
Create a file
The static method create
tries to create a file on a given path.
Returns true
on success or false
if not.
Checking if a file is writable
Load file lines
Returns the lines of a text file as an array
Parsing .env files
Parses the content of an env
file as an associative array.
Parsing .json files
Loads a JSON file content and returns it as an associative array.
In case of invalidation returns an empty array.
Parsing .key files
Loads a .key file content and returns the key from it.
The key file, is a text file that contains a key splitted in lines.
The key MUST be surrounded by -----BEGIN-----
and -----END-----
.
.key file example
TPass
Generates random passwords, and checks password strength
Options
Option | Type | Default | Description |
---|---|---|---|
includeLowercase | bool | true | Include lowercased letters |
includeUppercase | bool | true | Include uppercased letters |
includeNumbers | bool | true | Include numeric characters |
includeSymbols | bool | true | Include special characters |
beginWithALetter | bool | false | Password should begin with a letter |
[!NOTE] When enabling
beginWithALetter
assure thatincludeLowercase
orincludeUppercase
is enabled.
Setting symbols source
The default symbols source is !;#$%&()*+,-./:;<=>?@[]^_{|}~
;
To set a custom symbols source, use the method setSymbols
.
Checking password strength
To check the password strength use the method checkPasswordStrength
;
It returns an int value from 0 to 4, where:
Examples
TUID (Torugo Unique ID)
Generates a randomic unique ID with date and time.
This tool can generate three types of IDs:
Type | Length | Sample |
---|---|---|
Short | 20 | QJLM77R-TS0SHULDI0SH |
Medium | 26 | KMSEEBAN-NC7V-TM0SHULDI0U2 |
Long | 36 | PVA4M433-20L5-K1HVUPLQW-TL0SHULDI0VT |
Generating
Validating
Getting Date and Time
TRandom
Generates random strings and numbers
Random strings
Sets the source chars used to generate random strings.
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
alpha |
string | a...zA...Z | Alphabetical characters used to generate strings. |
numbers |
string | 0123456789 | Numerical characters used to generate strings. |
symbols |
string | !;#%&()*+,-./:;<=>?@[]^_{|}~ | Special characters used to generate strings. |
includeAlpha |
bool | true | Should include alphabetical chars. |
includeNumbers |
bool | true | Should include numbers. |
includeSymbols |
bool | true | Should include symbols. |
startWithAlphaChar |
bool | false | Should start with alphabetical characters. |
Setting the source characters
Random Numbers
Generates a random integer between the given range.
Random Numbers with leading zeros
Generates a positive random integer with leading zeros.
Traits
Empty Values Trait
Returns an empty value for a specific type.
From Array Factory
Instantiates a class from a key=>value array.
- The keys must be equal to the properties names.
- All properties must be setted as public.
Example
Contribute
It is currently not open to contributions, I intend to make it available as soon as possible.
License
This library is licensed under the MIT License - see the LICENSE file for details.
All versions of util with dependencies
ext-mbstring Version *
ext-openssl Version *