public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.xml');

        if (false === isset($config['mapping'])) {
            throw new \RuntimeException(__CLASS__.': mapping can\'t be empty');
        }

        $errorCode = empty($config['error_code']) ? 200 : $config['error_code'];

        /**
         * Cache.
         */
        $cacheId = empty($config['cache']) ? 'rpc.server.cache' : $config['cache'];

        if (!$container->hasDefinition($cacheId)) {
            $cacheDefinition = new Definition(
                'Doctrine\Common\Cache\FilesystemCache',
                ['%kernel.cache_dir%/rpc', '']
            );

            $cacheDefinition->setPublic(true);
            $container->setDefinition($cacheId, $cacheDefinition);
        }

        /**
         * Serializer.
         */
        $serializerId = empty($config['serializer']) ? 'rpc.server.serializer' : $config['serializer'];

        if (!$container->hasDefinition($serializerId)) {
            $serializerDefinition = new Definition(
                BaseSerializer::class,
                [new Reference('serializer', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
            );

            $serializerDefinition->setPublic(true);
            $container->setDefinition($serializerId, $serializerDefinition);
        }

        /**
         * Registry.
         */
        $registry = new Definition(HttpHandlerRegistry::class);

        /**
         * Mapping.
         *
         * @param string       $name
         * @param array|string $paths
         */
        $createMapping = function ($name, $paths) use ($cacheId, $serializerId, $container, $errorCode, $registry) {
            $name = empty($name) ? 'default' : $name;
            $mapperId = 'rpc.server.mapper.'.$name;

            $this->prepareMethods($mapperId, $paths, $container);

            $mapper = new Definition(Mapper::class);

            $mapper
                ->setPublic(true)
                ->addTag(MapperInterface::class); // Tag it for access from another place

            // Json Handler
            $jsonHandlerId = empty($name) ? 'rpc.server.json_handler' : 'rpc.server.json_handler.'.$name;
            $jsonHandler = new Definition(JsonHandler::class, [new Reference($mapperId), new Reference($serializerId)]);

            $jsonHandler->setPublic(true);
            $jsonHandler->addMethodCall(
                'setEventDispatcher',
                [new Reference('rpc.server.event_dispatcher', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
            );

            $jsonHandler->addMethodCall(
                'setCache',
                [new Reference($cacheId, ContainerInterface::NULL_ON_INVALID_REFERENCE)]
            );

            $jsonHandler->addMethodCall(
                'setContainer',
                [new Reference('service_container')]
            );

            // Http handler
            $httpHandlerId = empty($name) ? 'rpc.server.http_handler' : 'rpc.server.http_handler.'.$name;
            $httpHandler = new Definition(HttpHandler::class, [new Reference($jsonHandlerId), $errorCode]);

            $httpHandler->setPublic(true);
            $httpHandler->addMethodCall(
                'setEventDispatcher',
                [new Reference('rpc.server.event_dispatcher', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
            );

            $httpHandler->addMethodCall(
                'setProfiler',
                [new Reference('profiler', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
            );

            // Set definitions
            $container->setDefinition($mapperId, $mapper);
            $container->setDefinition($jsonHandlerId, $jsonHandler);
            $container->setDefinition($httpHandlerId, $httpHandler);

            // Add http handler to registry
            $registry->addMethodCall('add', [$name, new Reference($httpHandlerId)]);
        };

        $mapping = $config['mapping'];

        foreach ((array) $mapping as $key => $value) {
            if (\is_numeric($key)) {
                $createMapping(null, $value);
            } elseif (\is_string($key) && !empty($value)) {
                $createMapping($key, (array) $value);
            }
        }

        $container->setDefinition(HttpHandlerRegistry::class, $registry);
    }
public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.xml');

        if (false === isset($config['mapping'])) {
            throw new \RuntimeException(__CLASS__.': mapping can\'t be empty');
        }

        $errorCode = empty($config['error_code']) ? 200 : $config['error_code'];

        /**
         * Cache.
         */
        $cacheId = empty($config['cache']) ? 'rpc.server.cache' : $config['cache'];

        if (!$container->hasDefinition($cacheId)) {
            $cacheDefinition = new Definition(
                'Doctrine\Common\Cache\FilesystemCache',
                ['%kernel.cache_dir%/rpc', '']
            );

            $cacheDefinition->setPublic(true);
            $container->setDefinition($cacheId, $cacheDefinition);
        }

        /**
         * Serializer.
         */
        $serializerId = empty($config['serializer']) ? 'rpc.server.serializer' : $config['serializer'];

        if (!$container->hasDefinition($serializerId)) {
            $serializerDefinition = new Definition(
                BaseSerializer::class,
                [new Reference('serializer', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
            );

            $serializerDefinition->setPublic(true);
            $container->setDefinition($serializerId, $serializerDefinition);
        }

        /**
         * Registry.
         */
        $registry = new Definition(HttpHandlerRegistry::class);

        /**
         * Mapping.
         *
         * @param string       $name
         * @param array|string $paths
         */
        $createMapping = function ($name, $paths) use ($cacheId, $serializerId, $container, $errorCode, $registry) {
            $name = empty($name) ? 'default' : $name;
            $mapperId = 'rpc.server.mapper.'.$name;

            $this->prepareMethods($mapperId, $paths, $container);

            $mapper = new Definition(Mapper::class);

            $mapper
                ->setPublic(true)
                ->addTag(MapperInterface::class); // Tag it for access from another place

            // Json Handler
            $jsonHandlerId = empty($name) ? 'rpc.server.json_handler' : 'rpc.server.json_handler.'.$name;
            $jsonHandler = new Definition(JsonHandler::class, [new Reference($mapperId), new Reference($serializerId)]);

            $jsonHandler->setPublic(true);
            $jsonHandler->addMethodCall(
                'setEventDispatcher',
                [new Reference('rpc.server.event_dispatcher', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
            );

            $jsonHandler->addMethodCall(
                'setCache',
                [new Reference($cacheId, ContainerInterface::NULL_ON_INVALID_REFERENCE)]
            );

            $jsonHandler->addMethodCall(
                'setContainer',
                [new Reference('service_container')]
            );

            // Http handler
            $httpHandlerId = empty($name) ? 'rpc.server.http_handler' : 'rpc.server.http_handler.'.$name;
            $httpHandler = new Definition(HttpHandler::class, [new Reference($jsonHandlerId), $errorCode]);

            $httpHandler->setPublic(true);
            $httpHandler->addMethodCall(
                'setEventDispatcher',
                [new Reference('rpc.server.event_dispatcher', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
            );

            $httpHandler->addMethodCall(
                'setProfiler',
                [new Reference('profiler', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
            );

            // Set definitions
            $container->setDefinition($mapperId, $mapper);
            $container->setDefinition($jsonHandlerId, $jsonHandler);
            $container->setDefinition($httpHandlerId, $httpHandler);

            // Add http handler to registry
            $registry->addMethodCall('add', [$name, new Reference($httpHandlerId)]);
        };

        $mapping = $config['mapping'];

        foreach ((array) $mapping as $key => $value) {
            if (\is_numeric($key)) {
                $createMapping(null, $value);
            } elseif (\is_string($key) && !empty($value)) {
                $createMapping($key, (array) $value);
            }
        }

        $container->setDefinition(HttpHandlerRegistry::class, $registry);
    }
{@inheritdoc}

@throws \Exception