1. Go to this page and download the library: Download transprime-research/piper 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/ */
use Transprime\Piper\Piper;
// Normal
$piper = new Piper();
$piper->pipe(['AA'])->to('implode')->up();
// Better
$piper->on(['AA'])->to('implode')();
// Nifty
piper('AA')->to('strtolower')();
// Good
Piper::on('AA')->to('strtolower')->up();
//Better
Piper::on('AA')->to('strtolower')();
// test global method
piper('NAME', 'strtolower') // NAME becomes name
->to(fn($name) => ucfirst($name))
->up();
class StrManipulator
{
public function __invoke(string $value)
{
return $this->strToLower($value);
}
public static function strToLower(string $value)
{
return strtolower($value);
}
}
// test class method
piper('NAME', StrManipulator::class . '::strToLower')
->to(fn($name) => ucfirst($name))
->up();
// test array class and method
piper('NAME', [StrManipulator::class, 'strToLower'])
->to(fn($name) => ucfirst($name))
->up();
// test class object
piper('NAME', new StrManipulator()) // A class that implements __invoke
->to(fn($name) => ucfirst($name))
->up();