Skip to content

Commit 3336784

Browse files
authored
Merge pull request #4 from igrybkov/register-commands-properly
Remove excessive command creation
2 parents 8867586 + 09d6015 commit 3336784

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

Console/CommandList.php

+13-39
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Enqueue\Magento2\Console;
78

8-
use Enqueue\Symfony\Client\ConsumeMessagesCommand;
9-
use Enqueue\Symfony\Client\Meta\QueuesCommand;
10-
use Enqueue\Symfony\Client\Meta\TopicsCommand;
11-
use Enqueue\Symfony\Client\ProduceMessageCommand;
12-
use Enqueue\Symfony\Client\SetupBrokerCommand;
139
/**
1410
* Provides list of commands to be available for uninstalled application
1511
*/
@@ -70,22 +66,6 @@ public function __construct(
7066
$this->consumeMessagesCommandFactory = $consumeMessagesCommand;
7167
}
7268

73-
/**
74-
* Gets list of command classes
75-
*
76-
* @return string[]
77-
*/
78-
private function getCommandsClasses()
79-
{
80-
return [
81-
SetupBrokerCommand::class,
82-
ProduceMessageCommand::class,
83-
TopicsCommand::class,
84-
ConsumeMessagesCommand::class,
85-
QueuesCommand::class,
86-
];
87-
}
88-
8969
/**
9070
* @inheritdoc
9171
*/
@@ -96,24 +76,18 @@ public function getCommands()
9676
$this->enqueueManager->bindProcessors();
9777
$client = $this->enqueueManager->getClient();
9878

99-
foreach ($this->getCommandsClasses() as $class) {
100-
if (class_exists($class)) {
101-
$commands[] = $this->setupBrokerCommandFactory->create(['driver' => $client->getDriver()]);
102-
$commands[] = $this->produceMessageCommandFactory->create(['producer' => $client->getProducer()]);
103-
$commands[] = $this->queuesCommandFactory->create(['queueRegistry' => $client->getQueueMetaRegistry()]);
104-
$commands[] = $this->topicsCommandFactory->create(['topicRegistry' => $client->getTopicMetaRegistry()]);
105-
$commands[] = $this->consumeMessagesCommandFactory->create(
106-
[
107-
'consumer' => $client->getQueueConsumer(),
108-
'processor' => $client->getDelegateProcessor(),
109-
'queueMetaRegistry' => $client->getQueueMetaRegistry(),
110-
'driver' => $client->getDriver()
111-
]
112-
);
113-
} else {
114-
throw new \Exception('Class ' . $class . ' does not exist');
115-
}
116-
}
79+
$commands[] = $this->setupBrokerCommandFactory->create(['driver' => $client->getDriver()]);
80+
$commands[] = $this->produceMessageCommandFactory->create(['producer' => $client->getProducer()]);
81+
$commands[] = $this->queuesCommandFactory->create(['queueRegistry' => $client->getQueueMetaRegistry()]);
82+
$commands[] = $this->topicsCommandFactory->create(['topicRegistry' => $client->getTopicMetaRegistry()]);
83+
$commands[] = $this->consumeMessagesCommandFactory->create(
84+
[
85+
'consumer' => $client->getQueueConsumer(),
86+
'processor' => $client->getDelegateProcessor(),
87+
'queueMetaRegistry' => $client->getQueueMetaRegistry(),
88+
'driver' => $client->getDriver()
89+
]
90+
);
11791

11892
return $commands;
11993
}

0 commit comments

Comments
 (0)