Repository navigation
Expand file tree
/
Copy pathmodule.php
More file actions
38 lines (34 loc) · 1.63 KB
/
Copy pathmodule.php
File metadata and controls
38 lines (34 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
use Marko\Config\ConfigRepositoryInterface;
use Marko\Core\Container\ContainerInterface;
use Marko\PubSub\PublisherInterface;
use Marko\PubSub\Redis\Driver\RedisPublisher;
use Marko\PubSub\Redis\Driver\RedisSubscriber;
use Marko\PubSub\Redis\RedisPubSubConnection;
use Marko\PubSub\SubscriberInterface;
return [
'bindings' => [
PublisherInterface::class => RedisPublisher::class,
SubscriberInterface::class => RedisSubscriber::class,
RedisPubSubConnection::class => static function (ContainerInterface $container): RedisPubSubConnection {
$config = $container->get(ConfigRepositoryInterface::class);
// An app config that sets a key to null removes it (ConfigMerger
// unsets null overrides), so a missing key also means "no password".
$password = $config->has(key: 'pubsub-redis.password') ? $config->get(key: 'pubsub-redis.password') : null;
return new RedisPubSubConnection(
host: $config->getString(key: 'pubsub-redis.host'),
port: $config->getInt(key: 'pubsub-redis.port'),
password: $password === null || $password === '' ? null : (string) $password,
database: $config->getInt(key: 'pubsub-redis.database'),
prefix: $config->getString(key: 'pubsub.prefix'),
scheme: $config->getString(key: 'pubsub-redis.scheme'),
);
},
],
'singletons' => [
RedisPubSubConnection::class,
// One subscriber per process: all of its subscriptions share one Redis connection
SubscriberInterface::class,
],
];