You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-43Lines changed: 43 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,14 +17,14 @@
17
17
18
18
-[Requirements](#requirements)
19
19
-[How to install](#how-to-install)
20
-
-[What does it solve?](#what-does-it-solve)
21
-
-[A simple example](#a-simple-example)
22
-
-[Another way of writing](#another-way-of-writing)
23
-
-[More examples of the issue at hand](#more-examples-of-the-issue-at-hand)
24
20
-[How to use](#how-to-use)
25
21
-[The basics](#the-basics)
26
22
-[Using closures](#using-closures)
27
23
-[Using class methods](#using-class-methods)
24
+
-[What does it solve?](#what-does-it-solve)
25
+
-[A simple example](#a-simple-example)
26
+
-[Another way of writing](#another-way-of-writing)
27
+
-[More examples of the issue at hand](#more-examples-of-the-issue-at-hand)
28
28
-[Notes](#notes)
29
29
-[License](#license)
30
30
-[Change log](#change-log)
@@ -46,45 +46,6 @@ Via Composer:
46
46
composer require sebastiaanluca/php-pipe-operator
47
47
```
48
48
49
-
## What does it solve?
50
-
51
-
This package is based on the [pipe operator RFC by Sara Golemon (2016)](https://wiki.php.net/rfc/pipe-operator), who explains the problem as:
52
-
53
-
>A common PHP OOP pattern is the use of method chaining, or what is also known as “Fluent Expressions”. […] This works well enough for OOP classes which were designed for fluent calling, however it is impossible, or at least unnecessarily arduous, to adapt non-fluent classes to this usage style, harder still for functional interfaces.
54
-
55
-
Coming across the proposal, I also [blogged about it](https://blog.sebastiaanluca.com/enabling-php-method-chaining-with-a-makeshift-pipe-operator).
56
-
57
-
### A simple example
58
-
59
-
Say you want to get the subdomain from a URL, you end up with something like this:
60
-
61
-
```php
62
-
$subdomain = 'https://blog.sebastiaanluca.com/';
63
-
$subdomain = parse_url($subdomain, PHP_URL_HOST);
64
-
$subdomain = explode('.', $subdomain);
65
-
$subdomain = reset($subdomain);
66
-
67
-
// "blog"
68
-
```
69
-
70
-
This works, of course, but it's quite verbose and repetitive.
This might be the worst of all solutions, as it requires you to start reading from the center, work your way towards the outer methods, and keep switching back and forth. The more methods and variants, the more difficult to get a sense of what's going on.
83
-
84
-
### More examples of the issue at hand
85
-
86
-
See [Sara's RFC](https://wiki.php.net/rfc/pipe-operator#introduction) for more complex and real-world examples.
87
-
88
49
## How to use
89
50
90
51
### The basics
@@ -230,6 +191,45 @@ class MyClass
230
191
}
231
192
```
232
193
194
+
## What does it solve?
195
+
196
+
This package is based on the [pipe operator RFC by Sara Golemon (2016)](https://wiki.php.net/rfc/pipe-operator), who explains the problem as:
197
+
198
+
>A common PHP OOP pattern is the use of method chaining, or what is also known as “Fluent Expressions”. […] This works well enough for OOP classes which were designed for fluent calling, however it is impossible, or at least unnecessarily arduous, to adapt non-fluent classes to this usage style, harder still for functional interfaces.
199
+
200
+
Coming across the proposal, I also [blogged about it](https://sebastiaanluca.com/blog/enabling-php-method-chaining-with-a-makeshift-pipe-operator).
201
+
202
+
### A simple example
203
+
204
+
Say you want to get the subdomain from a URL, you end up with something like this:
205
+
206
+
```php
207
+
$subdomain = 'https://blog.sebastiaanluca.com/';
208
+
$subdomain = parse_url($subdomain, PHP_URL_HOST);
209
+
$subdomain = explode('.', $subdomain);
210
+
$subdomain = reset($subdomain);
211
+
212
+
// "blog"
213
+
```
214
+
215
+
This works, of course, but it's quite verbose and repetitive.
This might be the worst of all solutions, as it requires you to start reading from the center, work your way towards the outer methods, and keep switching back and forth. The more methods and variants, the more difficult to get a sense of what's going on.
228
+
229
+
### More examples of the issue at hand
230
+
231
+
See [Sara's RFC](https://wiki.php.net/rfc/pipe-operator#introduction) for more complex and real-world examples.
232
+
233
233
## Notes
234
234
235
235
While this packages makes a good attempt at bringing the pipe operator to PHP, it unfortunately does not offer autocompletion on chained methods. For that to work we need the real deal, so make some noise and get the people in charge to vote *for* Sara's RFC!
0 commit comments