Skip to content

Commit 244f52e

Browse files
committed
Updated docs
1 parent 3d5efb4 commit 244f52e

9 files changed

Lines changed: 47 additions & 36 deletions
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ title: What are callable collection in Sirius\Invokator?
66

77
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.
88

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`
1111

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.
1313

1414
Below it's an example for a collection designed to run as a pipeline that process a piece of text
1515

@@ -63,9 +63,11 @@ $processor = new PipelineProcessor($invoker);
6363
$processor->processCollection($callables, ' world ');
6464

6565
// 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
6971
```
7072

7173
Each type of callables processor has its own quirks that you can learn on the next page.

docs/2_3_command_bus.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $bus->register(CreateProductCommand::class, 'SomeClass@execute');
3939
You can add middlewares at any point in time, before or after registering the command handlers.
4040

4141
```php
42-
$bus->addMiddleware(CreateProductCommand::class, 'CommandMiddleware@execute');
42+
$bus->addMiddleware(CreateProductCommand::class, 'CommandMiddleware@execute', 100 /* priority (optional) */);
4343
```
4444

4545
[Next: Actions a la Wordpress](2_4_wordpress_actions.md)

docs/2_3_event_dispatcher.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ $dispatcher = new Dispatcher($listenerProvider, $invoker);
1919
$listenerProvider->subscribeTo(Event::class, 'some_callable', 0);
2020
$listenerProvider->subscribeOnceTo(Event::class, 'some_callable', 0);
2121

22-
// if you use the Sirius\Invokator\Event\ListenerProvider
22+
// if you use the \Sirius\Invokator\Event\ListenerProvider
2323
// the same results as above can also be achieved with
2424
$dispatcher->subscribeTo(Event::class, 'some_callable', 0);
2525
$dispatcher->subscribeOnceTo(Event::class, 'some_callable', 0);
26+
27+
// dispatch the event
28+
$dispatcher->dispatch(new Event());
2629
```
2730

2831
### Named events

docs/2_3_middlewares.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ use Sirius\Invokator\Processors\MiddlewareProcessor;
1818
$invoker = new Invoker($psr11Container);
1919
$processor = new MiddlewareProcessor($invoker);
2020

21-
$processor->get('dispatcher')
21+
$processor->get('http_handler')
2222
->add('CsrfCheckMiddleware')
2323
->add('TrimStringsMiddleware')
2424
->add('AuthMiddleware')
2525
->add('CacheMiddleware')
2626
->add('RouterMiddleware');
2727

28-
$processor->process('dispatcher', new HttpRequest);
28+
$processor->process('http_handler', new HttpRequest);
2929
```
3030

3131
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

docs/2_4_wordpress_actions.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Actions a la Wordpress
66

77
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.
88

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)
1010

1111
#### Use case
1212

@@ -17,17 +17,17 @@ use Sirius\Invokator\Processors\ActionsProcessor;
1717
$invoker = new Invoker($psr11Container);
1818
$processor = new ActionsProcessor($invoker);
1919

20-
$processor->add('save_post', 'validate_taxonomies', 0, 2); // callback, priority, no of arguments passed
21-
$processor->add('save_post', 'validate_acf_fields', 0, 2);
20+
$processor->add('save_post', 'validate_taxonomies', 0, 2); // callback, priority, number of arguments passed
21+
$processor->add('save_post', 'validate_acf_fields', 1, 2);
2222
$processor->add('save_post', 'check_permissions', 10, 1);
2323

2424
$processor->process('save_post', $postID, $wpPost, $update);
2525
```
2626

27-
**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
2828
```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
3131
```
3232

3333
[Next: Filters a la Wordpress](2_5_wordpress_filters.md)

docs/2_5_wordpress_filters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $processor->process('the_title', $postTitle, $postID);
2727

2828
```php
2929
$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
3131
```
3232

3333
[Next: Custom callable processors](2_6_custom_processors.md)

docs/2_6_custom_processors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ If you extend the `SimpleCallablesProcessor` you only need to implement the `pro
1010

1111
Here are some ideas:
1212
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.
1314

1415
[Next: callable modifiers](3_callable_modifiers.md)

docs/2_callable_processors.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ Callable processors are objects that have 3 objectives:
1010
3. To process collections stored in the registry via `$processor->process('callables_identifier', $param_1, $param_2)`
1111
4. To process callable collections constructed separately via `$processor->processCollection($previouslyConstructedCollection, $param_1, $param_2)`
1212

13-
The processors depend on the [invoker](3_the_invoker.md) to actually execute the callbacks.
13+
The processors depend on the [invoker](4_the_invoker.md) to actually execute the callbacks.
1414

1515
The `Sirius\Invokator` library comes with 5 callable processors/runners
1616
1. [simple collection](2_1_simple_collection.md)
1717
2. [pipelines](2_2_pipelines.md)
1818
3. [middlewares](2_3_middlewares.md)
1919
4. [actions a la Wordpress](2_4_wordpress_actions.md)
2020
5. [filters a la Wordpress](2_5_wordpress_filters.md)
21-
22-
You can also implement pretty easily your own [custom callables](2_6_custom_processors.md)
21+
6. [custom processors](2_6_custom_processors.md)

docs/3_callable_modifiers.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ use Sirius\Invokator\Processors\SimpleStackProcessor;
2424
$invoker = new Invoker($psr11Container);
2525
$processor = new SimpleStackProcessor($invoker);
2626

27-
$processor->get('collection')
27+
$processor->get('callables_collection')
2828
->add(limit_arguments(function($param_1, $param2) {
29-
return 'something'
29+
return 'something';
3030
}, 2))
3131
->add(limit_arguments('Service@method', 1));
3232

33-
$processor->process('collection', $param_1, $param_2, $param_3, $param_4);
33+
$processor->process('callables_collection', $param_1, $param_2, $param_3, $param_4);
3434
```
3535

36+
Even though this processor will receive 4 arguments, the callables will only receive 2 and 1 arguments respectively.
37+
3638
This modifier is used by the [actions processor](2_4_wordpress_actions.md) and the [filters processor](2_5_wordpress_filters.md)
3739

3840
## The "once" modifier
@@ -45,13 +47,13 @@ It is useful for an events system where you want a particular listener to be exe
4547

4648
```php
4749
use function Sirius\Invokator\once;
48-
$processor->get('add')
50+
$processor->get('callables_collection')
4951
->add(once(function($param_1, $param2) {
5052
return $param_1 + $param2
5153
}));
5254

53-
$processor->process('event', 2 + 3); // this returns 5
54-
$processor->process('event', 8 + 7); // this STILL returns 5
55+
$processor->process('callables_collection', 2, 3); // this returns 5
56+
$processor->process('callables_collection', 8, 7); // this STILL returns 5
5557
```
5658

5759
## The "wrap" modifier
@@ -62,33 +64,36 @@ This can be used to override how the callable is actually being executed by pass
6264

6365
```php
6466
use function Sirius\Invokator\wrap;
65-
$processor->get('collection')
67+
$processor->get('callables_collection')
6668
->add(wrap('Service@method', function(callable $callable) use ($param_3, $param_4) {
6769
return $callable($param_3, $param_4);
6870
}, 2));
6971

70-
$processor->process('collection', $param_1, $param_2);
71-
// the `Service@method` function will actually receive $param_3 and $param_4 as arguments instead of $param_1 and $param_2
72+
$processor->process('callables_collection', $param_1, $param_2);
7273
```
7374

75+
The `Service@method` function will actually receive $param_3 and $param_4 as arguments instead of $param_1 and $param_2
76+
7477
## The "with arguments" modifier
7578

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)
7780

7881
```php
7982
use function Sirius\Invokator\with_arguments;
8083
use function Sirius\Invokator\ref;
8184
use function Sirius\Invokator\arg;
82-
$processor->get('collection')
85+
$processor->get('callables_collection')
8386
->add(with_arguments('Service@method', [arg(0), 'value', ref('SomeClass'), arg(1)]);
8487

85-
$processor->process('collection', $param_1, $param_2);
86-
87-
// This is the same as calling Service@method($param_1, 'value', $container->get('SomeClass'), $param_2)
88+
$processor->process('callables_collection', $param_1, $param_2);
89+
//
8890
```
91+
92+
This is the same as calling `Service@method($param_1, 'value', $container->get('SomeClass'), $param_2)`
93+
8994
## The "resolve" modifier
9095

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.
9297

9398
The `resolve()` modifier works with the `arg()` and `ref()` utilities.
9499

@@ -101,9 +106,10 @@ $processor->get('collection')
101106
->add(resolve('Service@method', ['param_1' => arg(0), 'param_3' => 20]);
102107

103108
$processor->process('collection', 10);
104-
// $param_2 will be a
105109
```
106110

111+
This will call `Service@method(10, $container->get('SomeClass'), 20)`
112+
107113
You will learn about the `arg()` and `ref()` functions on the [invoker](4_the_invoker.md) page
108114

109115
[Next: The callable invoker](4_the_invoker.md)

0 commit comments

Comments
 (0)