PHP code example of danilovl / helper-utils

1. Go to this page and download the library: Download danilovl/helper-utils 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/ */

    

danilovl / helper-utils example snippets


use Danilovl\HelperUtils\Helper\Date\DateHelper;
use Danilovl\HelperUtils\Helper\String\StringHelper;
use Danilovl\HelperUtils\Helper\Network\IpHelper;

// Dates — explicit "now" for testability
$age  = DateHelper::calculateAge(new DateTimeImmutable('1990-04-25'));
$past = DateHelper::isPast($someDate, $now);

// Strings
$slug = StringHelper::slugify('Привет, мир!');           // "privet-mir"
$mask = StringHelper::maskEmail('[email protected]'); // "j******[email protected]"

// IP Utilities
$ok   = IpHelper::isIpInRange('192.168.1.5', '192.168.1.0/24');
$anon = IpHelper::anonymize('192.168.1.123');             // "192.168.1.0"

use Danilovl\HelperUtils\Service\RequestHelper;
use Danilovl\HelperUtils\Service\ClockAwareDateHelper;

public function __construct(
    private RequestHelper $requestHelper,
    private ClockAwareDateHelper $clock,
) {}

$ip  = $this->requestHelper->getClientIp();
$now = $this->clock->now(); // Easily mockable