Retrieve HydratorInterface object from service locator

@param ServiceLocatorInterface $serviceLocator
@param $name
@return HydratorInterface
@throws Exception\RuntimeException
326482
protected function getHydratorByName(ServiceLocatorInterface $serviceLocator, $name)
    {
        if ($serviceLocator->has('HydratorManager')) {
            $serviceLocator = $serviceLocator->get('HydratorManager');
        }

        $obj = $serviceLocator->get($name);
        if (!$obj instanceof HydratorInterface) {
            throw new Exception\RuntimeException(sprintf(
                'Instance of type %s is invalid; must implement %s',
                (is_object($obj) ? get_class($obj) : gettype($obj)),
                HydratorInterface::class
            ));
        }
        return $obj;
    }
149101
private function createCache(string $name)
	{
		$builder = $this->getContainerBuilder();

		$cache = $builder->addDefinition($this->prefix('cache.' . $name))
			->setClass(Cache::class)
			->setArguments(['@Nette\Caching\IStorage', $this->debugMode])
			->addSetup('$service->setNamespace(?)', [$this->prefix('cache.' . $name)]);

		return $cache;
	}
1327817
protected function getActiveRecordCriteriaByName($serviceLocator, $name)
    {
        $criteria = $serviceLocator->get($name);
        if (!$criteria instanceof AbstractCriteria) {
            throw new Exception\ServiceNotCreatedException(sprintf(
                'Instance of type %s is invalid; must implement %s',
                (is_object($criteria) ? get_class($criteria) : gettype($criteria)),
                AbstractCriteria::class
            ));
        }
        return $criteria;
    }
718503
protected function getParameter(string $name)
    {
        if (!$this->container->has('parameter_bag')) {
            throw new ServiceNotFoundException('parameter_bag', null, null, [], sprintf('The "%s::getParameter()" method is missing a parameter bag to work properly. Did you forget to register your controller as a service subscriber? This can be fixed either by using autoconfiguration or by manually wiring a "parameter_bag" in the service locator passed to the controller.', \get_class($this)));
        }

        return $this->container->get('parameter_bag')->get($name);
    }
1284723
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        $appServiceLocator = $serviceLocator;
        if ($serviceLocator instanceof AbstractPluginManager) {
            $appServiceLocator = $serviceLocator->getServiceLocator();
        }

        return $appServiceLocator->get($requestedName);
    }
870687
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        if (is_null($this->cachedFileGateway)) {
            $this->cachedFileGateway = new FileGateway(
                $serviceLocator->get('prooph.link.fileconnector.file_type_adapter_manager'),
                $serviceLocator->get('prooph.link.fileconnector.filename_renderer'),
                $serviceLocator->get('prooph.link.app.location_translator')
            );
        }

        return $this->cachedFileGateway;
    }
637375
public function getProvider($name)
    {
        if (!$name) {
            throw new \InvalidArgumentException('Provider name cannot be empty, did you forget to call setProviderName() in your Media object?');
        }
        if (empty($this->providers)) {
            throw new \RuntimeException(sprintf('Unable to retrieve provider named "%s" since there are no providers configured yet.', $name));
        }
        if (!isset($this->providers[$name])) {
            throw new \InvalidArgumentException(sprintf('Unable to retrieve the provider named "%s". Available providers are %s.', $name, '"'.implode('", "', $this->getProviderList()).'"'));
        }

        return $this->providers[$name];
    }
288369
public function get($name)
    {
        $instance = self::getInstance();
        if (!$instance->offsetExists($name)) {
            throw new \RuntimeException(sprintf('Class %s Not Found', $name));
        }

        return $instance->offsetGet($name);
    }
501191
protected function getRendererService($name)
    {
        if (!isset($this->renderers[$name])) {
            throw new \RuntimeException('The renderer "%s" does not exist.');
        }

        return $this->container->get($this->renderers[$name]);
    }
978618
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('Config');
        if (!isset($config['cache_manager'])) {
            throw new Exception\RuntimeException(
                'No cache manager config found.'
            );
        }
        $options = $config['cache_manager'];
        $manager = new CacheManager;
        foreach ($options as $key => $value) {
            if ($manager->hasCacheTemplate($key)) {
                $manager->setTemplateOptions($key, $value);
            } else {
                $manager->setCacheTemplate($key, $value);
            }
        }
        return $manager;
    }
1358691
public function getService($name = null)
    {
        $name = $name ?: $this->defaultService;

        if (!$name) {
            throw new \RuntimeException(sprintf(
                'You must configure a default %s service, registered %s services: "%s"',
                $this->serviceType, $this->serviceType,
                implode('", "', array_keys($this->services))
            ));
        }

        if (isset($this->services[$name])) {
            return $this->services[$name];
        }

        $this->assertServiceExists($name);
        $this->services[$name] = $this->container->get($this->serviceMap[$name]);

        return $this->services[$name];
    }
316989
public function get($name)
    {
        if ($this->exists($name)) {
            return $this->container[$name];
        } else {
            throw new RuntimeException(sprintf('Attempted to retrieve non-existing dependency "%s"', $name));
        }
    }
1045054
public static function getInstance(string $name): IPool
    {
        if(!isset(static::$pools[$name]))
        {
            throw new \RuntimeException(sprintf('GetInstance failed, %s is not found', $name));
        }
        return static::$pools[$name];
    }
517340
public function getManager($name)
    {
        $builder = $this->getBuilder($name);
        if (!$builder instanceof Builder) {
            throw new \RuntimeException(sprintf('"%s" is not a registered manager', $name));
        }

        $manager = $builder->getManager();

        $this->registerGlobalAnnotationLoader();

        return $manager;
    }
268440
public function getFilter($name)
    {
        if (!array_key_exists($name, $this->filters)) {
            throw new \RuntimeException('There is no filter for the name "' . $name . '" registered.');
        }

        return $this->filters[$name];
    }
1128600
public function get($name, array $params = array())
    {
        if (null === $this->serviceLocator) {
            throw new DomainException('No ServiceLocator defined, use `createServiceWithName` instead of `get`');
        }

        if (self::USE_SL_BEFORE_DI === $this->useServiceLocator && $this->serviceLocator->has($name)) {
            return $this->serviceLocator->get($name);
        }

        try {
            return parent::get($name, $params);
        } catch (ClassNotFoundException $e) {
            if (self::USE_SL_AFTER_DI === $this->useServiceLocator && $this->serviceLocator->has($name)) {
                return $this->serviceLocator->get($name);
            }

            throw new Exception\ServiceNotFoundException(
                sprintf('Service %s was not found in this DI instance', $name),
                null,
                $e
            );
        }
    }
289675
private function getFactoryMapping(ContainerInterface $serviceLocator, $name)
    {
        $matches = [];

        if (! preg_match(
            '/^doctrine\.((?<mappingType>orm|odm)\.|)(?<serviceType>[a-z0-9_]+)\.(?<serviceName>[a-z0-9_]+)$/',
            $name,
            $matches
        )) {
            return false;
        }

        $config      = $serviceLocator->get('config');
        $mappingType = $matches['mappingType'];
        $serviceType = $matches['serviceType'];
        $serviceName = $matches['serviceName'];

        if ($mappingType == '') {
            if (! isset($config['doctrine_factories'][$serviceType]) ||
                 ! isset($config['doctrine'][$serviceType][$serviceName])
            ) {
                return false;
            }

            return [
                'serviceType'  => $serviceType,
                'serviceName'  => $serviceName,
                'factoryClass' => $config['doctrine_factories'][$serviceType],
            ];
        } else {
            if (! isset($config['doctrine_factories'][$mappingType]) ||
                 ! isset($config['doctrine_factories'][$mappingType][$serviceType]) ||
                 ! isset($config['doctrine'][$mappingType][$serviceType][$serviceName])
            ) {
                return false;
            }
            return [
                'serviceType'  => $serviceType,
                'serviceName'  => $serviceName,
                'factoryClass' => $config['doctrine_factories'][$mappingType][$serviceType],
            ];
        }
    }