1. Go to this page and download the library: Download torugo/util library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
torugo / util example snippets
use Torugo\Util\CDT\CDT;
$cdt = CDT::get(); // returns something like "SGVU9Z2WV"
use Torugo\Util\DateWriter\DateWriter;
$dateTime = \DateTime::createFromFormat("Y-m-d H:i:s", "2017-08-01 15:30:45");
$dw = new DateWriter($dateTime, "pt");
$dw->write("[São Paulo,] j [de] %{F} [de] Y");
// São Paulo, 1 de agosto de 2017
$dw->write("*{l}");
// TERÇA-FEIRA
use Torugo\Util\SemVer\SemVer;
$version = new SemVer("1.0.0");
$version->compareTo("1.0.0"); // returns VersionComparison::Equal
$version->compareTo("1.0.1"); // returns VersionComparison::Smaller
$version->compareTo("1.0.0-beta"); // returns VersionComparison::Bigger
use Torugo\Util\TBase64\TBase64;
$b64 = TBase64::encode("My String"); // => "TXkgU3RyaW5n"
$decoded = TBase64::decode($b64); // => "My String"
use Torugo\Util\TEncrypt\TEncrypt;
use Torugo\Util\TEncrypt\Enums\TCipher;
$text = "May the force be with you!";
$key = "ye-PaJYnFPluROpIFo146zhQNvKHbUkIKNMc2rkd8rE";
$encrypted = TEncrypt::encrypt($text, $key,); // Encrypts the text
$decrypt = TEncrypt::decrypt($encrypted,$key); // Decrypts the encrypted text
$tuid = "PVA4M433-20L5-K1HVUPLQW-TL0SHULDI0VT";
TUID::getDateTime($tuid); // returns a PHP DateTime instance
use Torugo\Util\TRandom\TRandom;
$tRandom = new TRandom;
$rnd = $tRandom->string(10); // Generates 10 chars long random string
$random->alpha = "ABCDEF";
$random->numbers = "123";
$random->symbols = "#$%&*";
$str = $random->string(10);
// Generates a random string with the given characters.
$tRandom->number(1001, 9999); // Generates a random number between 1001 and 9999
use Torugo\Util\Traits\EmptyValues;
class MyClass {
use EmptyValues;
function myFunction() {
// ...
$type = $this->getEmptyValueForType(gettype($var));
// ...
}
}
use Torugo\Util\Traits\FromArrayFactory;
class UserDto
{
use FromArrayFactory;
public string $name;
public string $email;
public string $password;
}
$payload = [
"name" => "Full User Name",
"email" => "[email protected]",
"password" => "SuperStrongPassword!",
];
$instance = UserDto::fromArray($payload);
// $instance->name ==> "Full User Name"
// $instance->email ==> "[email protected]"
// $instance->password ==> "SuperStrongPassword!"