sebastiaanluca / php-pipe-operator Goto Github PK
View Code? Open in Web Editor NEWMethod chaining for any value using any method.
Home Page: https://sebastiaanluca.com
License: MIT License
Method chaining for any value using any method.
Home Page: https://sebastiaanluca.com
License: MIT License
Is there a specific reason you went for a pipe class instead of a simple pipe function, like:
function pipe() {
$args = func_get_args();
$result = $args[0];
$functions = array_slice($args, 1);
foreach ($functions as $function) {
$result = $function($result);
}
return $result;
}
Just curious. ^^
I do love the fluent code but wouldn't it be better to write a fluent interface? It would eliminate the need for PIPED_VALUE.
For example see the fluent strings in Laravel:
https://laravel.com/docs/8.x/helpers#fluent-strings
You could do the same for arrays and others.
Am I missing something?
Hi
It is very nice piece of work, I am using pipe-operator in my projects. It really rocks, especially in combination with symfony expression language.
When I upgraded to 5.x within php8 migration I noticed that some of my expressions need to be fix because of strict_types=1
.
I am wondering is declaring strict_types=1
is good for pipe-operator? What were the arguments for doing this?
As I understand the purpose of the pipe-operator it to make the code flow :), get it more compact and agile and so does the php coercive mode which is good thing in specific cases, changing it to strict_types in my opinion takes pipe-operator one step back in terms of agile.
For example:
class A
{
public function __toString(): string
{
return '[]';
}
}
take(new A())->json_decode()->get();
On version 3-4.x it executes with no errors, on version 5.x it ends with:
PHP Fatal error: Uncaught TypeError: json_decode(): Argument #1 ($json) must be of type string, A given in /home/psuw/xtm/projekty/portal/portal/vendor/sebastiaanluca/php-pipe-operator/src/Pipe.php:37
Of course it will work but it is not so compact:
take((string) new A())->json_decode()->get();
symfony expression language:
take(a.__toString()).json_decode().get()
It seems this is an abandoned project that does not support the latest PHP version. People looking for a good replacement can try boostphp/pipe-operator.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.