Skip to content

Commit e436e4d

Browse files
committed
update documentation
1 parent 7330a99 commit e436e4d

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

readme.md

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The incoming web request will be handled by `your_app_domain` + whatever you put
2121

2222
To get an overview of all functionalities this package offers, you can check the `tests/PipeRequestTest.php`.
2323

24-
**Handling Pipes**
24+
### Handling Pipes
2525

2626
Pipes are matched by the keys and values of the request's data attributes.
2727

@@ -67,14 +67,67 @@ If you want to handle multiple requests with different attribute keys you can us
6767
Pipe::any('{bar}', 'SomeController@index');
6868
```
6969

70-
**Other Options**
70+
### Other Options
7171

72-
// todo
72+
**alias()**
73+
Sometimes user might have a typo in their message or you simply want to have different cues available to trigger a Pipe.
7374

74-
- `alias()`
75-
- `namespace()`
76-
- `key()`
77-
- `where()`
75+
```php
76+
Pipe::any('bar', 'FooBarController')
77+
->alias(['ba', 'b-r', 'bas']);
78+
```
79+
80+
The `FooBarController` will now be called upon `ba`, `b-r`, `bas` or as originally intended on `bar`.
81+
82+
**namespace()**
83+
As you have probably noted the `routes/pipes.php` file is bound to a namespace configurable in the `config/pipes.php`. If you want to define a group with a different namespace, you can use the `namespace()` method:
84+
85+
```php
86+
Pipe::middleware('pipe')
87+
->namespace(config('pipes.namespace'))
88+
->group(function () {
89+
// define your namespaced pipes here
90+
});
91+
```
92+
93+
**key()**
94+
Like demonstrated in the first section of the *Handling Pipes* documentation, you can define Pipe routes in man different ways.
95+
96+
```php
97+
Pipe::match('foo', 'bar', function () {});
98+
99+
// same as
100+
Pipe::match('foo:bar', function () {});
101+
```
102+
103+
There is a third option to specify the `key` of a Pipe by using the `key()` method.
104+
105+
```php
106+
Pipe::key('foo')->match('bar', function () {});
107+
```
108+
109+
The key method is handy if you have got several pipe routes which reacts to the same key.
110+
111+
```php
112+
Pipe::key('text')
113+
->group(function () {
114+
// all pipe definitions within here will check for the `text` as key in the incoming request
115+
Pipe::match('some-text', function () {});
116+
});
117+
```
118+
119+
**where()**
120+
To further specify which request should be send to a specific handler you can define conditions on each pipe, like you are used to with [Laravel routes](https://laravel.com/docs/5.8/routing#parameters-regular-expression-constraints).
121+
122+
```php
123+
Pipe::any('{foo}', function ($foo) {
124+
return $foo;
125+
})->where('foo', 'bar');
126+
127+
Pipe::any('{foo}', function ($foo) {
128+
return $foo;
129+
})->where('foo', '[a-z]+');
130+
```
78131

79132
**Understanding Pipe Life Cycle**
80133

0 commit comments

Comments
 (0)