Skip to content

Commit 7c28399

Browse files
committed
Allow to merge with other configs
1 parent 229d77f commit 7c28399

File tree

7 files changed

+59
-9
lines changed

7 files changed

+59
-9
lines changed

src/CarrotMQ.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,40 @@ public function __construct($config = [], LoggerInterface $logger = null)
3636
$this->logger->debug(\vsprintf('Instance of "%s" has been created', [self::class]));
3737
}
3838

39+
/**
40+
* @return array
41+
*/
42+
public function getConfig(): array
43+
{
44+
return $this->config;
45+
}
46+
47+
/**
48+
* @param array $config
49+
*
50+
* @return $this
51+
*/
52+
public function setConfig(array $config): self
53+
{
54+
$this->config = $config;
55+
$this->container = null;
56+
57+
return $this;
58+
}
59+
60+
/**
61+
* @param array $config
62+
*
63+
* @return $this
64+
*/
65+
public function mergeWithConfig(array $config): self
66+
{
67+
$this->config = Config::create($this->config)->mergeWith($config)->toArray();
68+
$this->container = null;
69+
70+
return $this;
71+
}
72+
3973
/**
4074
* @return Container
4175
*/

src/Collection/BaseList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function clear()
8181
*/
8282
public function has($id)
8383
{
84-
return \array_key_exists($id, $this->items);
84+
return (isset($this->items[$id]) || \array_key_exists($id, $this->items));
8585
}
8686

8787
}

src/Component.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,27 @@ public function resetEvents()
7575
*
7676
* @return $this
7777
*/
78-
public function logger(LoggerInterface $logger)
78+
public function setLogger(LoggerInterface $logger)
7979
{
8080
$this->logger = $logger;
8181

8282
return $this;
8383
}
8484

85+
/**
86+
* @return LoggerInterface|NullLogger
87+
*/
88+
public function getLogger()
89+
{
90+
return $this->logger;
91+
}
92+
93+
/**
94+
* @return void
95+
*/
96+
public function __destruct()
97+
{
98+
unset($this->id, $this->events, $this->logger);
99+
}
100+
85101
}

src/Connection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public function __destruct()
6161
*
6262
* @return $this
6363
*/
64-
public function logger(LoggerInterface $logger)
64+
public function setLogger(LoggerInterface $logger)
6565
{
6666
$this->logger = $logger;
6767

68-
$this->driver->logger($this->logger);
68+
$this->driver->setLogger($this->logger);
6969

7070
return $this;
7171
}

src/Consumer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function __construct(
8989
$this->tag :
9090
\vsprintf('[host: %s]-[pid: %s]-[queue: %s]', [\gethostname(), \getmypid(), $this->queue->name()]);
9191

92-
$this->queue->logger($this->logger);
92+
$this->queue->setLogger($this->logger);
9393
}
9494

9595
/**
@@ -140,7 +140,7 @@ protected function prepare()
140140
}
141141

142142
/* @var Extension $extension */
143-
$extension->logger($this->logger);
143+
$extension->setLogger($this->logger);
144144

145145
$this->events->addSubscriber($extension);
146146
}
@@ -151,7 +151,7 @@ protected function prepare()
151151
|--------------------------------------------------------------------------
152152
|
153153
*/
154-
$this->queue->logger($this->logger);
154+
$this->queue->setLogger($this->logger);
155155

156156
if ($this->queue->canAutoCreate()) {
157157
$this->queue->install();

src/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function logger(LoggerInterface $logger)
112112
/* @var BaseList $context */
113113
foreach ($this->{$context}->all() as $entry) {
114114
/* @var Component $entry */
115-
$entry->logger($logger);
115+
$entry->setLogger($logger);
116116
}
117117
}
118118

src/Publisher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(
6060
$this->topic = $topic;
6161
$this->config = Config::create(static::DEFAULTS)->mergeWith($config)->toArray();
6262

63-
$this->topic->logger($this->logger);
63+
$this->topic->setLogger($this->logger);
6464

6565
$context = $this->topic->connection()->context(true);
6666

0 commit comments

Comments
 (0)