configParser = $configParser; $this->defaultValueProvider = $defaultValueProvider; } /** * {@inheritDoc} */ public function convert($source) { $result = []; /** @var $consumerNode \DOMElement */ foreach ($source->getElementsByTagName('consumer') as $consumerNode) { $consumerName = $this->getAttributeValue($consumerNode, 'name'); $handler = $this->getAttributeValue($consumerNode, 'handler'); $result[$consumerName] = [ 'name' => $consumerName, 'queue' => $this->getAttributeValue($consumerNode, 'queue'), 'consumerInstance' => $this->getAttributeValue( $consumerNode, 'consumerInstance', self::$defaultInstance ), 'handlers' => $handler ? [$this->parseHandler($handler)] : [], 'connection' => $this->getAttributeValue( $consumerNode, 'connection', $this->defaultValueProvider->getConnection() ), 'maxMessages' => $this->getAttributeValue($consumerNode, 'maxMessages') ]; } return $result; } /** * Get attribute value of the given node * * @param \DOMNode $node * @param string $attributeName * @param mixed $default * @return string|null */ private function getAttributeValue(\DOMNode $node, $attributeName, $default = null) { $item = $node->attributes->getNamedItem($attributeName); return $item ? $item->nodeValue : $default; } /** * Parse service method callback to become compatible with handlers format. * * @param array $handler * @return array */ private function parseHandler($handler) { $parseServiceMethod = $this->configParser->parseServiceMethod($handler); return [ CommunicationConfig::HANDLER_TYPE => $parseServiceMethod[ConfigParser::TYPE_NAME], CommunicationConfig::HANDLER_METHOD => $parseServiceMethod[ConfigParser::METHOD_NAME] ]; } }