Skip to content

Commit

Permalink
phpdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Nov 7, 2024
1 parent 394c50f commit 7a8601c
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/Provider/AdapterFactoryQueueProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
use function array_key_exists;
use function sprintf;

/**
* Queue provider based on adapter definitions.
*
* @see https://github.com/yiisoft/definitions/
* @see https://github.com/yiisoft/factory/
*/
final class AdapterFactoryQueueProvider implements QueueProviderInterface
{
/**
Expand All @@ -23,6 +29,11 @@ final class AdapterFactoryQueueProvider implements QueueProviderInterface
private readonly StrictFactory $factory;

/**
* @param QueueInterface $baseQueue Base queue to use for creating queues.
* @param array $definitions Definitions to create adapters with indexed by channel names.
* @param ContainerInterface|null $container Container to use for resolving dependencies.
* @param bool $validate If definitions should be validated when set.
*
* @psalm-param array<string, mixed> $definitions
* @throws InvalidQueueConfigException
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Provider/ChannelNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

use function sprintf;

/**
* Thrown when channel is not found.
*/
final class ChannelNotFoundException extends LogicException implements QueueProviderException
{
public function __construct(string $channel, int $code = 0, ?Throwable $previous = null)
Expand Down
6 changes: 6 additions & 0 deletions src/Provider/CompositeQueueProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@

use Yiisoft\Queue\QueueInterface;

/**
* Composite queue provider.
*/
final class CompositeQueueProvider implements QueueProviderInterface
{
/**
* @var QueueProviderInterface[]
*/
private readonly array $providers;

/**
* @param QueueProviderInterface ...$providers Queue providers to use.
*/
public function __construct(
QueueProviderInterface ...$providers
) {
Expand Down
3 changes: 3 additions & 0 deletions src/Provider/InvalidQueueConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use LogicException;

/**
* Thrown when queue configuration is invalid.
*/
final class InvalidQueueConfigException extends LogicException implements QueueProviderException
{
}
7 changes: 7 additions & 0 deletions src/Provider/PrototypeQueueProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

use Yiisoft\Queue\QueueInterface;

/**
* Queue provider that only changes the channel name of the base queue.
* It can be useful when your queues used the same adapter.
*/
final class PrototypeQueueProvider implements QueueProviderInterface
{
/**
* @param QueueInterface $baseQueue Base queue to use for creating queues.
*/
public function __construct(
private readonly QueueInterface $baseQueue,
) {
Expand Down
10 changes: 10 additions & 0 deletions src/Provider/QueueFactoryQueueProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
use function array_key_exists;
use function sprintf;

/**
* Queue provider based on queue definitions.
*
* @see https://github.com/yiisoft/definitions/
* @see https://github.com/yiisoft/factory/
*/
final class QueueFactoryQueueProvider implements QueueProviderInterface
{
/**
Expand All @@ -22,6 +28,10 @@ final class QueueFactoryQueueProvider implements QueueProviderInterface
private readonly StrictFactory $factory;

/**
* @param array $definitions Definitions to create queues with indexed by channel names.
* @param ContainerInterface|null $container Container to use for resolving dependencies.
* @param bool $validate If definitions should be validated when set.
*
* @psalm-param array<string, mixed> $definitions
* @throws InvalidQueueConfigException
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Provider/QueueProviderException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Throwable;

/**
* Base interface representing a generic exception in a queue provider.
*/
interface QueueProviderException extends Throwable
{
}
22 changes: 19 additions & 3 deletions src/Provider/QueueProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@

use Yiisoft\Queue\QueueInterface;

/**
* `QueueProviderInterface` provides a way to get a queue instance by channel name.
*/
interface QueueProviderInterface
{
/**
* @throws InvalidQueueConfigException
* @throws ChannelNotFoundException
* @throws QueueProviderException
* Find a queue by channel name and returns it.
*
* @param string $channel Channel name.
*
* @return QueueInterface Queue instance.
*
* @throws InvalidQueueConfigException If the queue configuration is invalid.
* @throws ChannelNotFoundException If the channel is not found.
* @throws QueueProviderException If the queue provider fails to provide a queue.
*/
public function get(string $channel): QueueInterface;

/**
* Check if a queue with the specified channel name exists.
*
* @param string $channel Channel name.
*
* @return bool Whether the queue exists.
*/
public function has(string $channel): bool;
}

0 comments on commit 7a8601c

Please sign in to comment.