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: docs/1_callable_collection.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,10 @@ title: What are callable collection in Sirius\Invokator?
6
6
7
7
In the `Sirius\Invokator` items in the callable collections are organized by priority. By default, the priority is determined by the order the callables are added to the collection. The callables are executed in the order of their priority.
8
8
9
-
A **callable** is something that can be executed directly or after being interpreted by the [invoker](2_the_invoker.md). For example the `Invoker` class that comes with this library can recognize and execute callables in the form of
10
-
`SomeClass@someMethod`
9
+
A **callable** is something that can be executed directly or after being interpreted by the [invoker](4_the_invoker.md).
10
+
For example the `Invoker` class that comes with this library can recognize and execute callables in the form of `SomeClass@someMethod`
11
11
12
-
Even though callable collections may have different purposes (middleware, events etc), a collection is defined in a single way.
12
+
Even though callable collections may have different purposes (middleware, events, etc.), a collection is defined in a single way.
13
13
14
14
Below it's an example for a collection designed to run as a pipeline that process a piece of text
15
15
@@ -63,9 +63,11 @@ $processor = new PipelineProcessor($invoker);
63
63
$processor->processCollection($callables, ' world ');
64
64
65
65
// this will
66
-
// 1. create string `HELLO WORLD`,
67
-
// 2. Write an info message to the logger
68
-
// 3. send it to a SlackChannel
66
+
// 1. trim the parameter => `world`
67
+
// 2. concatenate with "hello " => `hello world`
68
+
// 3. make the string uppercase => `HELLO WORLD`,
69
+
// 4. write the string as an info message to the logger
70
+
// 5. send the string to a SlackChannel
69
71
```
70
72
71
73
Each type of callables processor has its own quirks that you can learn on the next page.
Copy file name to clipboardExpand all lines: docs/2_3_middlewares.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,14 +18,14 @@ use Sirius\Invokator\Processors\MiddlewareProcessor;
18
18
$invoker = new Invoker($psr11Container);
19
19
$processor = new MiddlewareProcessor($invoker);
20
20
21
-
$processor->get('dispatcher')
21
+
$processor->get('http_handler')
22
22
->add('CsrfCheckMiddleware')
23
23
->add('TrimStringsMiddleware')
24
24
->add('AuthMiddleware')
25
25
->add('CacheMiddleware')
26
26
->add('RouterMiddleware');
27
27
28
-
$processor->process('dispatcher', new HttpRequest);
28
+
$processor->process('http_handler', new HttpRequest);
29
29
```
30
30
31
31
While this example is for HTTP middleware, it does not implement the [PSR-15 middleware specifications](https://www.php-fig.org/psr/psr-15/) as it does not enforce their respective signatures. It would be up to your app to enforce those restrictions
Copy file name to clipboardExpand all lines: docs/2_4_wordpress_actions.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ title: Actions a la Wordpress
6
6
7
7
This processor is similar to the "Simple callables processor" with the difference that you also have to specify a limit for the arguments passed to each callable.
8
8
9
-
This means that the callables do not have to have the same signature as for the SimpleCallables processor. This processor is just a convenience as the same result could be been achieved using the ['limit_arguments' modifier](4_callable_modifiers.md)
9
+
This means that the callables do not have to have the same signature as for the SimpleCallables processor. This processor is just a convenience as the same result could be been achieved using the ['limit_arguments' modifier](3_callable_modifiers.md)
10
10
11
11
#### Use case
12
12
@@ -17,17 +17,17 @@ use Sirius\Invokator\Processors\ActionsProcessor;
17
17
$invoker = new Invoker($psr11Container);
18
18
$processor = new ActionsProcessor($invoker);
19
19
20
-
$processor->add('save_post', 'validate_taxonomies', 0, 2); // callback, priority, no of arguments passed
**Attention!** The processor's `get()` and `add()` method return the Stack object, so you can't chain callables with arguments limit. For example the code below doesn't work as you might expect
27
+
**Attention!** The processor's `get()` and `add()` method return the callables collection, so you can't chain callables with arguments limit. For example the code below doesn't work as you might expect
28
28
```php
29
-
$processor->add('save_post', 'validate_taxonomies', 0, 2) // this returns the collection
30
-
->add('validate_acf_fields', 0, 2); // this won't place a limit on the arguments for the 'validate_acf_fields' function
29
+
$processor->add('save_post', 'validate_taxonomies', 0, 2) // this returns the callables collection
30
+
->add('validate_acf_fields', 0, 2); // this won't place a limit on the arguments for the 'validate_acf_fields' function since the callables is returned by the first add() call
31
31
```
32
32
33
33
[Next: Filters a la Wordpress](2_5_wordpress_filters.md)
$processor->add('the_title', 'add_category_name', 0, 2) // this returns the collection
30
-
->add('add_site_name', 0, 2) // this won't place a limit on the arguments for the 'add_site_name' function
30
+
->add('add_site_name', 0, 2) // this won't place a limit on the arguments for the 'add_site_name' function since the callables is returned by the first add() call
Copy file name to clipboardExpand all lines: docs/2_6_custom_processors.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,5 +10,6 @@ If you extend the `SimpleCallablesProcessor` you only need to implement the `pro
10
10
11
11
Here are some ideas:
12
12
1. pipelines where all the callbacks receive the same arguments and where the result of a callback becomes the first argument in the list. It would be similar to the "Filters processor" but without having to specify the limit for the arguments.
13
+
2. HTTP middleware implementation of the PSR-15 standard. It would be similar to the "Middlewares processor" but with the restriction that all the callables should have the same signature.
The `Service@method` function will actually receive $param_3 and $param_4 as arguments instead of $param_1 and $param_2
76
+
74
77
## The "with arguments" modifier
75
78
76
-
This modifier can be used when you have a callable that has a specific signature, and you don't want to change its signature nor do you want to wrap it inside an anonymous function (eg: because you want to serialize the collection)
79
+
This modifier can be used when you have a callable that has a specific signature, and you don't want to change its signature nor do you want to wrap it inside an anonymous function (eg: because you might need to serialize the collection)
This is the same as calling `Service@method($param_1, 'value', $container->get('SomeClass'), $param_2)`
93
+
89
94
## The "resolve" modifier
90
95
91
-
Some callables might have dependencies on other services, and you might not know them while you call them or you might not want to be forced to use `ref()` them. In this case you can use the `resolve()` modifier.
96
+
Some callables might have dependencies on other services, and you might not know them while you call them, or you might not want to be forced to use `ref()` them. In this case you can use the `resolve()` modifier.
92
97
93
98
The `resolve()` modifier works with the `arg()` and `ref()` utilities.
0 commit comments