defaultValueProvider = $defaultValueProvider; $this->objectManagerConfig = $objectManagerConfig; $this->reflectionGenerator = $reflectionGenerator; $this->serviceMethodsMap = $serviceMethodsMap; } /** * {@inheritdoc} */ public function read($scope = null) { $exchangeName = $this->defaultValueProvider->getExchange(); return [ $exchangeName => [ 'name' => $exchangeName, 'type' => 'topic', 'connection' => $this->defaultValueProvider->getConnection(), 'durable' => true, 'autoDelete' => false, 'internal' => false, 'bindings' => $this->generateBindings(), 'arguments' => [], ] ]; } /** * Generate list of bindings based on information about remote services declared in DI config. * * @return array * * @throws \LogicException * * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ private function generateBindings() { $bindings = []; foreach ($this->getRemoteServices() as $serviceInterface => $remoteImplementation) { try { $methodsMap = $this->serviceMethodsMap->getMethodsMap($serviceInterface); } catch (\Exception $e) { throw new \LogicException(sprintf('Service interface was expected, "%s" given', $serviceInterface)); } foreach ($methodsMap as $methodName => $returnType) { $topic = $this->reflectionGenerator->generateTopicName($serviceInterface, $methodName); $exchangeName = $this->defaultValueProvider->getExchange(); $destination = 'queue.' . $topic; $id = $topic . '--' . $exchangeName . '--' . $destination; $bindings[$id] = [ 'id' => $id, 'destinationType' => 'queue', 'destination' => $destination, 'disabled' => false, 'topic' => $topic, 'arguments' => [] ]; } } return $bindings; } /** * Get list of remote services declared in DI config. * * @return array */ private function getRemoteServices() { $preferences = $this->objectManagerConfig->getPreferences(); $remoteServices = []; foreach ($preferences as $type => $preference) { if ($preference == $type . RemoteServiceGenerator::REMOTE_SERVICE_SUFFIX) { $remoteServices[$type] = $preference; } } return $remoteServices; } }