Create service with name

@param ServiceLocatorInterface $serviceLocator
@param $name
@param $requestedName
@return mixed
976586
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        $config = $this->getConfig($serviceLocator)[$requestedName];

        $resourceName = $config['resource_name'];

        /** @var $httpClient Client */
        $httpClient = isset($config['http_client']) && $serviceLocator->has($config['http_client']) ?
            $serviceLocator->get($config['http_client']) : null;

        /** @var $baseRequest Request */
        $baseRequest = isset($config['base_request']) && $serviceLocator->has($config['base_request']) ?
            $serviceLocator->get($config['base_request']) : null;

        $restClient = new RestClient($resourceName, $httpClient, $baseRequest);

        if (isset($config['uri_resource_strategy']) && $serviceLocator->has($config['uri_resource_strategy'])) {
            $restClient->setUriResourceStrategy($serviceLocator->get($config['uri_resource_strategy']));
        }

        // Array of int code valid
        if (isset($config['valid_status_code']) && is_array($config['valid_status_code'])) {
            $restClient->setValidStatusCodes($config['valid_status_code']);
        }
        // string json/xml
        if (isset($config['request_format'])) {
            $restClient->setRequestFormat($config['request_format']);
        }
        // Profiler
        if (isset($config['profiler']) && $serviceLocator->has($config['profiler'])) {
            $restClient->setProfiler($serviceLocator->get($config['profiler']));
        }

        return $restClient;
    }
157696
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $context = new RequestContext();
        $context->fromRequest($serviceLocator->get('Request'));

        return $context;
    }
416360
protected function getConfig($requestedName, ServiceLocatorInterface $services)
    {
        if ($this->configKey) {
            $config = $services->get('Config');
            if (!empty($config[$this->configKey][$requestedName])
                && is_array($config[$this->configKey][$requestedName])
            ) {
                return $config[$this->configKey][$requestedName];
            }
        }

        return [];
    }
1221418
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        return $this->getContainer($serviceLocator)->has($requestedName);
    }
1120614
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var ModuleOptionsPluginManagerInterface $moduleOptionsManager */
        $moduleOptionsManager = $serviceLocator->get(ModuleOptionsPluginManagerInterface::class);

        /** @var DoctrineObjectManagerInterface $doctrineObjectManager */
        $doctrineObjectManager = $serviceLocator->get(DoctrineObjectManagerInterface::class);

        return new ObjectManagerAutoDetector($moduleOptionsManager, $doctrineObjectManager);
    }
461444
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $routeCollection = new RouteCollection();
        $requestContext  = $serviceLocator->get('RouterRequestContext');
        $routerOptions   = array();

        $logger = $serviceLocator->has('logger') ? $serviceLocator->get('Logger') : null;

        $router = new Router($requestContext, $routeCollection, $routerOptions, $logger);

        // @todo - consider making a base router class, and then have a ModuleRouterFactory to pull module routes
        // @todo - find a way to set routes on this after we instantiate this factory

        // @todo - let you add new routes on demand and call $router->setRouteCollection()
        return $router;
    }
685407
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        $config = $this->getConfig($serviceLocator)[$requestedName];
        /** @var $mongodb \MongoDb */
        $mongodb = $serviceLocator->get($config['database']);
        return $mongodb->selectCollection($config['collection']);
    }
473218
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        if (substr($requestedName, 0, 11) != 'FileStorage') {
            return false;
        }
        if (!($configs = $this->getConfigs($serviceLocator))) {
            return false;
        }

        return isset($configs[$requestedName]);
    }
292345
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        $config = $serviceLocator->get('config');
        $class = $this->getClass($config, $requestedName);
        return $class && class_exists($class);
    }
375652
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        /** @var $env Environment */
        $env = $serviceLocator->get(Definition::SERVICE_ENVIRONMENT);

        $nameParts = explode('.', $requestedName);

        Assertion::min(count($nameParts), 3, sprintf("Given service bus alias %s is invalid. Format should be processing.(command|event)_bus.[target]", $requestedName));

        $busType = $nameParts[1];

        unset($nameParts[0]);
        unset($nameParts[1]);

        $address = implode('.', $nameParts);

        $busConfig = $this->getChannelConfigFor($env, $address);
        $target    = $this->getTargetFromAddress($address);

        $bus = ($busType === "command_bus")? new CommandBus() : new EventBus();

        $bus->utilize($this->getForwardToMessageDispatcher());

        $bus->utilize($this->getToMessageTranslator());

        $bus->utilize($this->getHandleWorkflowMessageStrategy());

        $bus->utilize($this->getInvokeProcessorStrategy());

        $bus->utilize(new ServiceLocatorProxy(Zf2ServiceManagerProxy::proxy($serviceLocator)));

        $messageHandler = $busConfig->stringValue('message_dispatcher', $target);

        if (! empty($messageHandler)) {
            $bus->utilize(new SingleTargetMessageRouter($messageHandler));
        } else {
            throw new \LogicException("Missing a message handler for the bus " . $requestedName);
        }

        foreach ($busConfig->arrayValue('utils') as $busUtil) {
            if (is_string($busUtil)) {
                $busUtil = $serviceLocator->get($busUtil);
            }

            $bus->utilize($busUtil);
        }

        return $bus;
    }
80949
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        $this->init($serviceLocator);
        return $this->getDoctrineObjectHydratorLocator()->has($requestedName);
    }
1022944
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $className = $this->getClassName();
        $keyName   = $this->getKeyName();
        $config    = $serviceLocator->get('config');
        $options   = isset($config[$keyName]) ? $config[$keyName] : [];
        return new $className($options);
    }
781624
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        /** @var $config ProcessingConfig */
        $config = $serviceLocator->get("processing_config");

        $connector = $config->getConnectors()[$requestedName];


        if (! isset($connector['dbal_connection'])) throw new \InvalidArgumentException(sprintf('Missing dbal_connection for sql connector %s', $requestedName));
        if (! isset($connector['table'])) throw new \InvalidArgumentException(sprintf('Missing table definition for sql connector %s', $requestedName));

        $appConfig = $serviceLocator->get('config');


        if (! isset($appConfig['prooph.link.sqlconnector']['connections'][$connector['dbal_connection']])) throw new \InvalidArgumentException(sprintf('The DBAL connection %s can not be found. Please check config/autoload/sqlconnector.local.php!', $connector['dbal_connection']));

        $actionEventDispatcher = null;
        $listeners = null;

        if (isset($appConfig['prooph.link.sqlconnector']['action_listeners'][$requestedName])) {
            $actionEventDispatcher = new Zf2ActionEventDispatcher([$requestedName]);

            if (! is_array($appConfig['prooph.link.sqlconnector']['action_listeners'][$requestedName])) {
                throw new \InvalidArgumentException(
                    sprintf(
                        "Key prooph.link.sqlconnector.action_listeners.$requestedName of config should be of type array. Got %s",
                        gettype($appConfig['prooph.link.sqlconnector']['action_listeners'][$requestedName])
                    )
                );
            }

            foreach ($appConfig['prooph.link.sqlconnector']['action_listeners'][$requestedName] as $listenerAlias) {
                $listenerAggregate = $serviceLocator->get($listenerAlias);

                if (! $listenerAggregate instanceof ActionEventListenerAggregate) {
                    throw new \InvalidArgumentException(
                        sprintf(
                            "Action listeners for sqlconnector %s should be of type Prooph\\Common\\ActionEventListenerAggregate. Got %s",
                            $requestedName,
                            (is_object($listenerAggregate))? get_class($listenerAggregate) : gettype($listenerAggregate)
                        )
                    );
                }

                $listeners[] = $listenerAggregate;
            }
        }

        return new DoctrineTableGateway(
            DriverManager::getConnection($appConfig['prooph.link.sqlconnector']['connections'][$connector['dbal_connection']]),
            $connector['table'],
            $actionEventDispatcher,
            $listeners
        );
    }
689236
protected function mergeMvcConfig(ServiceLocatorInterface $serviceLocator, string $requestedName = null)
    {
        $config = $serviceLocator->has('config') ? $serviceLocator->get('config') : [];

        if (! isset($config['bsb_flysystem']['adapters'][$requestedName]['options']) ||
            ! is_array(($config['bsb_flysystem']['adapters'][$requestedName]['options']))
        ) {
            return;
        }

        $this->options = ArrayUtils::merge(
            $config['bsb_flysystem']['adapters'][$requestedName]['options'],
            $this->options
        );
    }
457589
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /**
         * @var array $config
         */
        $config = $serviceLocator->get('config');

        /**
         * @var \Zend\View\HelperPluginManager $serverUrl
         */
        $serverUrl = $serviceLocator->get('ViewHelperManager');

        /**
         * @var \Zend\Mvc\I18n\Translator $translator
         */
        $translator = $serviceLocator->get('translator');

        return new Search(
            $config,
            $serverUrl,
            $translator
        );
    }
985031
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $serviceName, $requestedName)
    {
        if (!isset($this->allowedServiceNames[$requestedName])) {
            throw new Exception\InvalidServiceNameException('Service "' . $requestedName . '" is not whitelisted');
        }


        if ($serviceLocator instanceof AbstractPluginManager) {
            /* @var $serviceLocator AbstractPluginManager */
            $this->serviceLocator = $serviceLocator->getServiceLocator();
        } else {
            $this->serviceLocator = $serviceLocator;
        }

        return parent::get($requestedName);
    }
1175703
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        try {
            $di = $this->getDiContainer($serviceLocator);
        } catch (\Exception $e) {
            return false;
        }

        $class = str_replace('.', '\\', $requestedName);
        if (class_exists($class) || $di->instanceManager()->hasAlias($requestedName)) {
            return true;
        }

        return false;
    }