alecrabbit / php-accessories
PHP Accessories: Classes etc.
Fund package maintenance!
Patreon
Installs: 4 095
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.2
- alecrabbit/php-helpers: ^0.6 || ^0.7 || ^0.8
- alecrabbit/php-reports: ^0.3
- alecrabbit/php-traits: ^0.3
Requires (Dev)
- nunomaduro/collision: ^3.0
- phpunit/phpunit: ^8.0
- symfony/var-dumper: ^4.3
This package is auto-updated.
Last update: 2024-10-29 05:22:54 UTC
README
Installation
composer require alecrabbit/php-accessories
Usage
for details see examples
Features
Caller::class
Gets a caller Class::method()
or function()
or Undefined
$caller = Caller::get() // object(AlecRabbit\Accessories\Caller\CallerData)
Note:
CallerData::class
can be casted to string
if($wrongArguments) { throw new \RuntimeException(Caller::get() . ' provided wrong arguments'); }
You can set your custom formatter for string casting:
$formatter = new CustomFormatter($options); Caller::setFormatter($formatter);
Note:
CustomFormatter::class
should implementCallerDataFormatterInterface
Circular::class
Helper class to get values in a circle
$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)
Note:
Circular::__construct
can acceptarray
,Rewindable
or callable which returns\Generator
Rewindable::class
Rewindable generator helper class
$r = new Rewindable($genFunc); // $genFunc is a callable and returns \Generator iterator_to_array($r); $r->rewind();
G::class
Contains generator functions
$r = G::range(1, 3); // object(Generator)
R::class
Contains rewindable generator functions
$r = R::range(1, 3); // object(AlecRabbit\Accessories\Rewindable) iterator_to_array($r); $r->rewind();
Pretty::class
String formatter, e.g. percent, bytes and time(seconds, microseconds, nanoseconds)
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"
Note: time formatting methods of
Pretty::class
named by units they are accepting
MemoryUsage::class
Helper class to get memory usage
$report = MemoryUsage::reportStatic('mb'); echo $report . PHP_EOL; // Memory: 0.75MB(32.73MB) Real: 2.00MB(34.00MB)
You can set your custom formatter for string casting:
$formatter = new CustomFormatter($options); MemoryUsage::setFormatter($formatter);
Note:
CustomFormatter::class
should implementMemoryUsageReportFormatterInterface
Note: Parameter
$options
has no effect onMemoryUsageReportFormatter