Skip to content

Remove excessive command creation #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 13 additions & 39 deletions Console/CommandList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Enqueue\Magento2\Console;

use Enqueue\Symfony\Client\ConsumeMessagesCommand;
use Enqueue\Symfony\Client\Meta\QueuesCommand;
use Enqueue\Symfony\Client\Meta\TopicsCommand;
use Enqueue\Symfony\Client\ProduceMessageCommand;
use Enqueue\Symfony\Client\SetupBrokerCommand;
/**
* Provides list of commands to be available for uninstalled application
*/
Expand Down Expand Up @@ -70,22 +66,6 @@ public function __construct(
$this->consumeMessagesCommandFactory = $consumeMessagesCommand;
}

/**
* Gets list of command classes
*
* @return string[]
*/
private function getCommandsClasses()
{
return [
SetupBrokerCommand::class,
ProduceMessageCommand::class,
TopicsCommand::class,
ConsumeMessagesCommand::class,
QueuesCommand::class,
];
}

/**
* @inheritdoc
*/
Expand All @@ -96,24 +76,18 @@ public function getCommands()
$this->enqueueManager->bindProcessors();
$client = $this->enqueueManager->getClient();

foreach ($this->getCommandsClasses() as $class) {
if (class_exists($class)) {
$commands[] = $this->setupBrokerCommandFactory->create(['driver' => $client->getDriver()]);
$commands[] = $this->produceMessageCommandFactory->create(['producer' => $client->getProducer()]);
$commands[] = $this->queuesCommandFactory->create(['queueRegistry' => $client->getQueueMetaRegistry()]);
$commands[] = $this->topicsCommandFactory->create(['topicRegistry' => $client->getTopicMetaRegistry()]);
$commands[] = $this->consumeMessagesCommandFactory->create(
[
'consumer' => $client->getQueueConsumer(),
'processor' => $client->getDelegateProcessor(),
'queueMetaRegistry' => $client->getQueueMetaRegistry(),
'driver' => $client->getDriver()
]
);
} else {
throw new \Exception('Class ' . $class . ' does not exist');
}
}
$commands[] = $this->setupBrokerCommandFactory->create(['driver' => $client->getDriver()]);
$commands[] = $this->produceMessageCommandFactory->create(['producer' => $client->getProducer()]);
$commands[] = $this->queuesCommandFactory->create(['queueRegistry' => $client->getQueueMetaRegistry()]);
$commands[] = $this->topicsCommandFactory->create(['topicRegistry' => $client->getTopicMetaRegistry()]);
$commands[] = $this->consumeMessagesCommandFactory->create(
[
'consumer' => $client->getQueueConsumer(),
'processor' => $client->getDelegateProcessor(),
'queueMetaRegistry' => $client->getQueueMetaRegistry(),
'driver' => $client->getDriver()
]
);

return $commands;
}
Expand Down