handlers = $handlers; } public function registerSubscribingHandler(SubscribingHandlerInterface $handler): void { foreach ($handler->getSubscribingMethods() as $methodData) { if (!isset($methodData['type'], $methodData['format'])) { throw new RuntimeException(sprintf('For each subscribing method a "type" and "format" attribute must be given, but only got "%s" for %s.', implode('" and "', array_keys($methodData)), \get_class($handler))); } $directions = [GraphNavigatorInterface::DIRECTION_DESERIALIZATION, GraphNavigatorInterface::DIRECTION_SERIALIZATION]; if (isset($methodData['direction'])) { $directions = [$methodData['direction']]; } foreach ($directions as $direction) { $method = $methodData['method'] ?? self::getDefaultMethod($direction, $methodData['type'], $methodData['format']); $this->registerHandler($direction, $methodData['type'], $methodData['format'], [$handler, $method]); } } } /** * {@inheritdoc} */ public function registerHandler(int $direction, string $typeName, string $format, $handler): void { $this->handlers[$direction][$typeName][$format] = $handler; } /** * {@inheritdoc} */ public function getHandler(int $direction, string $typeName, string $format) { if (!isset($this->handlers[$direction][$typeName][$format])) { return null; } return $this->handlers[$direction][$typeName][$format]; } }