Skip to content

Commit e4e4468

Browse files
committed
Docs clarification
1 parent 09b7174 commit e4e4468

7 files changed

Lines changed: 33 additions & 34 deletions

docs/guide/en/callable-definitions-extended.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ As you can see in the [PHP documentation](https://www.php.net/manual/en/language
5757

5858
## Type 2: Callable definition extensions (via container)
5959

60-
Under the hood, extended callable definitions behave exactly like native callables. But there is a major difference:
61-
all the objects are instantiated automatically by a PSR-11 DI container with all their dependencies
62-
and in a lazy way (only when they are needed).
60+
The difference from native PHP callables is that you don't need to instantiate objects yourself: you pass a class name or alias, and the DI container resolves the instance lazily, only when the callable is actually invoked.
6361
Ways to define an extended callable:
6462

6563
- An object method through a class name or alias:
@@ -76,14 +74,17 @@ Ways to define an extended callable:
7674

7775
$callable = [Foo::class, 'bar'];
7876
```
79-
Here is a simplified example of how it works:
77+
Here is a simplified example of how it works (for non-static methods):
8078
```php
8179
if ($container->has($callable[0])) {
8280
$callable[0] = $container->get($callable[0])
8381
}
84-
82+
8583
$callable();
8684
```
85+
86+
> [!NOTE]
87+
> If `bar` is declared `static`, no object is instantiated — the method is called statically on the class.
8788
- Class name of an object with [the `__invoke` method](https://www.php.net/manual/en/language.oop5.magic.php#object.invoke) implemented:
8889
```php
8990
$callable = Foo::class;

docs/guide/en/console-commands.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ If you are using [yiisoft/config](https://github.com/yiisoft/config) and [yiisof
66

77
If you are using [symfony/console](https://github.com/symfony/console) directly, you should register the commands manually.
88

9+
> **Note:** The default queue name list (used when no queue names are passed to a command) is only available when using [yiisoft/config](https://github.com/yiisoft/config) and [yiisoft/yii-console](https://github.com/yiisoft/yii-console). Without them, you must pass the queue name list explicitly to the command constructor.
10+
911
In [yiisoft/app](https://github.com/yiisoft/app) the `yii` console binary is provided out of the box.
1012
If you are using [yiisoft/console](https://github.com/yiisoft/console) or `symfony/console` without that template, invoke these commands the same way you invoke other console commands in your application.
1113

@@ -15,7 +17,7 @@ The command `queue:run` obtains and handles messages until the queue is empty, t
1517

1618
You can also narrow the scope of processed messages by specifying queue name(s) and maximum number of messages to process:
1719

18-
- Specify one or more queue names to process. Messages from other queues will be ignored. Default is all registered queue names (in case of using [yiisoft/config](https://github.com/yiisoft/config) and [yiisoft/yii-console](https://github.com/yiisoft/yii-console), otherwise pass the default queue name list to the command constructor).
20+
- Specify one or more queue names to process. Messages from other queues will be ignored. Defaults to all registered queue names.
1921
- Use `--limit` to limit the number of messages processed. When set, command will exit either when all the messages are processed or when the maximum count is reached.
2022

2123
The full command signature is:
@@ -35,12 +37,10 @@ yii queue:listen [queueName]
3537
3638
The following command iterates through multiple queues and is meant to be used in development environment only, as it consumes a lot of CPU for iterating through queues. You can pass to it:
3739
38-
- `queueName` argument(s). Specify one or more queue names to process. Messages from other queues will be ignored. Default is all registered queue names (in case of using [yiisoft/config](https://github.com/yiisoft/config) and [yiisoft/yii-console](https://github.com/yiisoft/yii-console), otherwise pass the default queue name list to the command constructor).
40+
- `queueName` argument(s). Specify one or more queue names to process. Messages from other queues will be ignored. Defaults to all registered queue names.
3941
- `--limit` option to limit the number of messages processed before switching to another queue. E.g. you set `--limit` to 500 and right now you have 1000 messages in `queue1`. This command will consume only 500 of them, then it will switch to `queue2` to see if there are any messages there. Defaults to `0` (no limit).
4042
- `--pause` option to specify the number of seconds to pause between checking queues when no messages are found. Defaults to `1`.
4143
42-
`queue:listen` does not have a `--limit` option. If you need to stop after processing a certain number of messages, use `queue:run --limit=...`.
43-
4444
The full command signature is:
4545
```sh
4646
yii queue:listen-all [queueName1 [queueName2 [...]]] --pause=1 --limit=0

docs/guide/en/envelopes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ An envelope implements `Yiisoft\Queue\Message\EnvelopeInterface`, which itself e
66

77
## How an envelope behaves
88

9-
An envelope acts like the wrapped message:
9+
An envelope is transparent to callers: it delegates the wrapped message's handler name and data unchanged.
1010

1111
- `getHandlerName()` is delegated to the wrapped message.
1212
- `getData()` is delegated to the wrapped message.

docs/guide/en/message-handler-simple.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ final class RemoteFileHandler implements \Yiisoft\Queue\Message\MessageHandlerIn
3333
**Pros**:
3434

3535
- Minimal configuration.
36-
- Rename-safe within the same application (rename class and producer together).
36+
- Rename-safe within the same application (rename both the class and the message creation code together).
3737
- Easy to unit-test the handler as a normal class.
3838

3939
**Cons**:
4040

41-
- Couples message names to PHP class names.
42-
- Requires producer and consumer to share the same naming contract (typically the same app).
41+
- Message names are PHP class names — works only when message creation and handler live in the same codebase.
4342

4443
**Use when**:
4544

docs/guide/en/message-handler.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Message handler advanced
22

3-
This page covers named handler definitions, callable formats, pitfalls, and recommended implementation styles.
3+
This page covers named handler definitions, callable formats, pitfalls, and valid handler signatures.
44

5-
For the zero-config FQCN approach (same-app producer and consumer), see [Message handler: simple setup](message-handler-simple.md).
5+
If you haven't read [Message handler: simple setup](message-handler-simple.md) yet, start there — it introduces handler classes and the zero-config FQCN approach.
66
For a conceptual overview of what messages and handlers are, see [Messages and handlers: concepts](messages-and-handlers.md).
77

88
Handler definitions are configured in:
@@ -36,9 +36,8 @@ return [
3636
];
3737
```
3838

39-
Handler definition should be either an [extended callable definition](./callable-definitions-extended.md) or a string for your DI container to resolve a `MessageHandlerInterface` instance.
39+
Handler definition should be either an [extended callable definition](./callable-definitions-extended.md) or a container identifier that resolves to a `MessageHandlerInterface` instance.
4040

41-
For the simpler FQCN-based approach that requires no mapping, see [Message handler: simple setup](message-handler-simple.md).
4241

4342
## When mapping by short names is a better idea
4443

@@ -65,18 +64,18 @@ This way external producers never need to know your internal PHP class names.
6564

6665
## Common pitfalls and unsupported formats
6766

68-
- A class-string that is not resolvable via `$container->has()` will not be auto-instantiated.
67+
- A PHP class name that is not registered in the DI container will not be auto-instantiated.
6968
- [yiisoft/definitions](https://github.com/yiisoft/definitions) array format (like `['class' => ..., '__construct()' => ...]`) is **not** supported for handlers.
7069

71-
## Recommended handler implementation styles
70+
## Valid handler signatures
7271

73-
- Prefer a dedicated handler class registered in DI.
74-
- For maximal compatibility with the worker resolution rules either:
75-
- Implement `MessageHandlerInterface`
76-
- Make the handler invokable (`__invoke(MessageInterface $message): void`)
77-
- Provide `[HandlerClass::class, 'handle']` and keep `handle(MessageInterface $message): void` as the entry point
72+
The worker recognises three callable signatures:
7873

79-
## Config location ([yiisoft/config](https://github.com/yiisoft/config))
74+
- `MessageHandlerInterface` — implement the interface; the worker calls `handle(MessageInterface $message): void` directly (covered in [simple setup](message-handler-simple.md)).
75+
- Invokable class — add `__invoke(MessageInterface $message): void`.
76+
- Explicit method — reference as `[HandlerClass::class, 'handle']` with `handle(MessageInterface $message): void` as the entry point.
77+
78+
## Config location (yiisoft/config)
8079

8180
When using [yiisoft/config](https://github.com/yiisoft/config), configure handlers under the [`yiisoft/queue`](https://github.com/yiisoft/queue) params key:
8281

@@ -90,4 +89,4 @@ return [
9089
];
9190
```
9291

93-
This config is consumed by the DI definitions from `config/di.php` where the `Worker` is constructed with `$params['yiisoft/queue']['handlers']`.
92+
This config is consumed by the DI definitions from [`config/di.php`](../../../config/di.php) where the `Worker` is constructed with `$params['yiisoft/queue']['handlers']`.

docs/guide/en/migrating-from-yii2-queue.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ being consumed. In the new package, it is divided into two different concepts: a
2323

2424
All the message data is fully serializable (that means message `data` must be serializable too). It allows you to
2525
freely choose where and how to send and process messages. Both can be implemented in a single application, or
26-
separated into multiple applications, or you can do sending/processing only leaving part of the work to another
27-
system including non-PHP ones. It is fairly popular to process heavy messages with Go.
26+
separated into multiple applications, or you can do sending/processing only, leaving part of the work to another
27+
system including non-PHP ones (for example, a Go service handling CPU-intensive jobs).
2828

2929
- A `Handler` is called by a `Worker` when a message is received. Default `Worker` finds a corresponding message handler
3030
by the message name. [See more](message-handler.md).

docs/guide/en/queue-names-advanced.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Advanced queue name internals
22

3-
Use this reference when you need to understand how queue names map to adapters, how providers resolve queues, and how to extend the registry.
3+
Use this reference when you need to understand how queue names map to adapters, how providers resolve queues, and how to implement your own provider.
44

55
## How queue names are used in code
66

@@ -23,7 +23,7 @@ This package ships four provider strategies:
2323
- Backed by the `yiisoft/queue.queues` params array.
2424
- Each queue name maps to an adapter definition.
2525
- Uses `yiisoft/factory` to create adapters lazily, then wraps them in a `Queue` with the given name.
26-
- Enforces a strict registry: unknown queue names throw `QueueNotFoundException` immediately.
26+
- Enforces a strict name mapping: unknown queue names throw `QueueNotFoundException` immediately.
2727

2828
### PredefinedQueueProvider
2929

@@ -70,7 +70,7 @@ $queueForEmails = $provider->get('emails');
7070

7171
- Accepts multiple providers and queries them in order.
7272
- The first provider whose `has()` returns true for the queue name wins.
73-
- Useful for mixing strict registries with pre-built queues.
73+
- Useful for mixing multiple providers, for example combining adapter-based and pre-built queues.
7474

7575
Example:
7676

@@ -87,8 +87,8 @@ $provider = new CompositeQueueProvider(
8787
$queueForEmails = $provider->get('emails');
8888
```
8989

90-
## Extending the registry
90+
## Implementing a custom provider
9191

92-
- Implement `QueueProviderInterface` if you need bespoke selection logic (e.g., tenant-specific registries, remote lookups, or metrics-aware routing).
92+
- Implement `QueueProviderInterface` if you need bespoke selection logic (e.g., tenant-specific routing, remote lookups, or metrics-aware routing).
9393
- Register your provider in the DI container and swap it in wherever `QueueProviderInterface` is used.
94-
- Consider exposing diagnostics (e.g., list of available queues) through `getNames()`, console commands, or health checks so operators can verify the registry at runtime.
94+
- Consider exposing diagnostics (e.g., list of available queues) through `getNames()`, console commands, or health checks so operators can verify the available queues at runtime.

0 commit comments

Comments
 (0)