morfu / pipe
Invokable pipeline of functions.
0.1.1
2022-11-12 23:40 UTC
Requires
- php: >=5.5.9
Requires (Dev)
- phpunit/phpunit: 4.8.28 - 5.0.9||>=5.6.3
- squizlabs/php_codesniffer: ^3.0
This package is not auto-updated.
Last update: 2025-05-17 00:34:15 UTC
README
NOT for production. API is NOT stable.
Why?
Instead of doing
$string = 'SCREAMING_SNAKE_CASE';
$string = strtolower($string);
$words = explode('_', $string);
$words = array_map('ucfirst', $words);
$camelized = implode('', $words);
// => 'ScreamingSnakeCase'
do
flow('SCREAMING_SNAKE_CASE', pipe()
->_('strtolower')
->left('explode', '_')
->left('array_map', 'ucfirst')
->left('implode', ''));
// => 'ScreamingSnakeCase'
For further examples see tests/
.
What is Morfu
Morfu (from Ancient Greek: μετᾰμορφόω, metamorphóō, "transform") is a set of pipeline-oriented PHP libraries.
What is Pipe
Pipe is a core library of Morfu that provides pipepline itself and some functions that act on other functions.
Install
Via Composer
$ composer require morfu/pipe
Usage
Import functions
use function Morfu\Pipe\functions\through;
$term = through(" tErm\t", 'trim', 'strtolower', 'ucfirst');
If your PHP version is less than 5.6 you should import parent namespace and use functions with the namespace prefix:
use Morfu\Pipe\functions as f;
$term = f\through(" tErm\t", 'trim', 'strtolower', 'ucfirst');
Testing
$ make test
Security
If you discover any security related issues, please email kilych@zoho.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.