Commit efa23105 authored by Ильнур Табулдин's avatar Ильнур Табулдин
Browse files

Добавлено управление controllerMap

parent 8a02036b
Showing with 29 additions and 0 deletions
+29 -0
......@@ -5,7 +5,9 @@ namespace deck\ModelEvent\handle;
use PhpAmqpLib\Connection\AbstractConnection;
use PhpAmqpLib\Connection\Heartbeat\PCNTLHeartbeatSender;
use Yii;
use yii\base\InvalidConfigException;
use yii\di\Instance;
use yii\helpers\Inflector;
use yii\helpers\VarDumper;
use yii\queue\amqp_interop\Queue as OriginalQueue;
use yii\queue\InvalidJobException;
......@@ -22,6 +24,8 @@ class EventQueue extends OriginalQueue
public $serializer = EventHandlerSerializer::class;
/** @var EventHandlerFactoryInterface $handlerFactory */
public $handlerFactory;
/** @var ?string $moduleName */
public $moduleName = null;
public function init()
{
......@@ -93,4 +97,29 @@ class EventQueue extends OriginalQueue
$this->sender->unregister();
}
}
protected function getCommandId()
{
if ($this->moduleName === null) {
return parent::getCommandId();
}
foreach (Yii::$app->getModule($this->moduleName)->getComponents(false) as $id => $component) {
if ($component === $this) {
return Inflector::camel2id($id);
}
}
throw new InvalidConfigException("Queue must be an $this->moduleName component.");
}
public function bootstrap($app)
{
if ($this->moduleName === null) {
parent::bootstrap($app);
} else {
$app->getModule($this->moduleName)->controllerMap[$this->getCommandId()] = [
'class' => $this->commandClass,
'queue' => $this
] + $this->commandOptions;
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment