PHP code example of alecrabbit / php-accessories

1. Go to this page and download the library: Download alecrabbit/php-accessories 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/ */

    

alecrabbit / php-accessories example snippets


$caller = Caller::get() // object(AlecRabbit\Accessories\Caller\CallerData)

if($wrongArguments) {
 throw new \RuntimeException(Caller::get() . ' provided wrong arguments'); 
}

$formatter = new CustomFormatter($options);
Caller::setFormatter($formatter);

$c = new Circular([1, 2, 3]);
$value = $c(); // int(1) invoke 
$value = $c->value(); // int(2) get value by method
... 
$c(); // int(3)
...
$c(); // int(1)

$r = new Rewindable($genFunc); // $genFunc is a callable and returns \Generator
iterator_to_array($r);
$r->rewind();

$r = G::range(1, 3);  // object(Generator)

$r = R::range(1, 3); // object(AlecRabbit\Accessories\Rewindable)
iterator_to_array($r);
$r->rewind();

Pretty::bytes(10584760, 'mb'); // string(7) "10.09MB"
Pretty::time(0.214); // string(5) "214ms"
Pretty::percent(0.214);  // string(6) "21.40%"

Pretty::seconds(0.214); // string(5) "214ms"

Pretty::milliseconds(214); // string(5) "214ms"

Pretty::useconds(3212); // string(5) "3.2ms"
Pretty::useconds(12); // string(5) "12μs"
// alias for useconds
Pretty::microseconds(12); // string(5) "12μs"

Pretty::nanoseconds(10485); // string(7) "10.5μs"
Pretty::nanoseconds(105); // string(7) "105ns"

$report = MemoryUsage::reportStatic('mb');
echo $report . PHP_EOL;
// Memory: 0.75MB(32.73MB) Real: 2.00MB(34.00MB)

$formatter = new CustomFormatter($options);
MemoryUsage::setFormatter($formatter);
bash
composer