/** * Extract topics configuration. * * @param \DOMDocument $config * @return array */ protected function extractTopics($config) { $output = []; /** @var $topicNode \DOMNode */ foreach ($config->getElementsByTagName('topic') as $topicNode) { $topicAttributes = $topicNode->attributes; $topicName = $topicAttributes->getNamedItem('name')->nodeValue; $serviceMethod = $this->getServiceMethodBySchema($topicNode); $requestResponseSchema = $serviceMethod ? $this->reflectionGenerator->extractMethodMetadata($serviceMethod['typeName'], $serviceMethod['methodName']) : null; $requestSchema = $this->extractTopicRequestSchema($topicNode); $responseSchema = $this->extractTopicResponseSchema($topicNode); $handlers = $this->extractTopicResponseHandlers($topicNode); $this->xmlValidator->validateResponseRequest($requestResponseSchema, $requestSchema, $topicName, $responseSchema, $handlers); $this->xmlValidator->validateDeclarationOfTopic($requestResponseSchema, $topicName, $requestSchema, $responseSchema); if ($serviceMethod) { $output[$topicName] = $this->reflectionGenerator->generateTopicConfigForServiceMethod($topicName, $serviceMethod['typeName'], $serviceMethod['methodName'], $handlers); } else { if ($requestSchema && $responseSchema) { $output[$topicName] = [Config::TOPIC_NAME => $topicName, Config::TOPIC_IS_SYNCHRONOUS => true, Config::TOPIC_REQUEST => $requestSchema, Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_CLASS, Config::TOPIC_RESPONSE => $responseSchema, Config::TOPIC_HANDLERS => $handlers]; } else { if ($requestSchema) { $output[$topicName] = [Config::TOPIC_NAME => $topicName, Config::TOPIC_IS_SYNCHRONOUS => false, Config::TOPIC_REQUEST => $requestSchema, Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_CLASS, Config::TOPIC_RESPONSE => null, Config::TOPIC_HANDLERS => $handlers]; } } } } return $output; }
/** * Extract topics configuration. * * @param \DOMDocument $config * @return array */ protected function extractTopics($config) { $output = []; /** @var $topicNode \DOMNode */ foreach ($config->getElementsByTagName('topic') as $topicNode) { $topicAttributes = $topicNode->attributes; $topicName = $topicAttributes->getNamedItem('name')->nodeValue; $requestResponseSchema = $this->extractSchemaDefinedByServiceMethod($topicNode); $requestSchema = $this->extractTopicRequestSchema($topicNode); $responseSchema = $this->extractTopicResponseSchema($topicNode); $handlers = $this->extractTopicResponseHandlers($topicNode); $this->xmlValidator->validateResponseRequest($requestResponseSchema, $requestSchema, $topicName, $responseSchema, $handlers); $this->xmlValidator->validateDeclarationOfTopic($requestResponseSchema, $topicName, $requestSchema, $responseSchema); if ($requestResponseSchema) { $output[$topicName] = [Config::TOPIC_NAME => $topicName, Config::TOPIC_IS_SYNCHRONOUS => true, Config::TOPIC_REQUEST => $requestResponseSchema[Config::SCHEMA_METHOD_PARAMS], Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_METHOD, Config::TOPIC_RESPONSE => $requestResponseSchema[Config::SCHEMA_METHOD_RETURN_TYPE], Config::TOPIC_HANDLERS => $handlers ?: ['defaultHandler' => $requestResponseSchema[Config::SCHEMA_METHOD_HANDLER]]]; } else { if ($requestSchema && $responseSchema) { $output[$topicName] = [Config::TOPIC_NAME => $topicName, Config::TOPIC_IS_SYNCHRONOUS => true, Config::TOPIC_REQUEST => $requestSchema, Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_CLASS, Config::TOPIC_RESPONSE => $responseSchema, Config::TOPIC_HANDLERS => $handlers]; } else { if ($requestSchema) { $output[$topicName] = [Config::TOPIC_NAME => $topicName, Config::TOPIC_IS_SYNCHRONOUS => false, Config::TOPIC_REQUEST => $requestSchema, Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_CLASS, Config::TOPIC_RESPONSE => null, Config::TOPIC_HANDLERS => $handlers]; } } } } return $output; }