Create API client

@param ContainerBuilder $container
@param $apiClient
@param $baseUrl
@param $type
@throws \LogicException
432230
protected function createApiClient(ContainerBuilder $container, $apiClient, $baseUrl, $type)
    {
        if ($apiClient == 'guzzle') {
            // Create an API client service
            $apiClientDefinition = new Definition(
                'Bluetea\Api\Client\GuzzleClient',
                array($baseUrl, new Reference(sprintf('jira_rest_api.%s_authentication', $type)))
            );
            $apiClientDefinition->addMethodCall('setContentType', array('application/json'));
            $apiClientDefinition->addMethodCall('setAccept', array('application/json'));
        } else {
            throw new \LogicException('Invalid api client');
        }
        $container->setDefinition(sprintf('jira_rest_api.%s_api_client', $type), $apiClientDefinition);
    }
712545
protected function createElasticsearchClient(ContainerBuilder $container, $name, $config)
    {
        $definitionId = 'm6web_elasticsearch.client.'.$name;

        $handlerId = $this->createHandler($container, $config, $definitionId);

        $clientConfig = [
            'hosts'   => $config['hosts'],
            'handler' => new Reference($handlerId),
        ];

        if (isset($config['retries'])) {
            $clientConfig['retries'] = $config['retries'];
        }

        if (isset($config['logger'])) {
            $clientConfig['logger'] = new Reference($config['logger']);
        }

        if (!empty($config['connectionPoolClass'])) {
            $clientConfig['connectionPool'] = $config['connectionPoolClass'];
        }

        if (!empty($config['selectorClass'])) {
            $clientConfig['selector'] = $config['selectorClass'];
        }

        if (!empty($config['connectionParams'])) {
            $clientConfig['connectionParams'] = $config['connectionParams'];
        }

        $definition = (new Definition($config['client_class']))
            ->setArguments([$clientConfig]);
        $this->setFactoryToDefinition($config['clientBuilderClass'], 'fromConfig', $definition);

        $container->setDefinition($definitionId, $definition);

        if ($container->getParameter('kernel.debug')) {
            $this->createDataCollector($container);
        }
    }
516618
public static function create(ContainerInterface $container, Request $request = null)
    {
        if (!isset($request)) {
            $request = $container['request'];
        }

        $view = new Smarty(__DIR__.'/../templates/');
        if (in_array('https', $request->getHeader('X-Forwarded-Proto'))) {
            $request = $request->withUri($request->getUri()->withScheme('https')->withPort(443));
        }

        $smartyPlugins = new SmartyPlugins($container['router'], $request->getUri()->withUserInfo(null));
        $view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']);
        $view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']);

        return $view;
    }
805980
public function create($name, CredentialsInterface $credentials, StorageInterface $storage, $scopes = [], $baseApiUri = null, $apiVersion = null)
    {
      $name = ucfirst($name);

      if(is_null($this->client))
        $this->client = new CurlClient();

      $class = '\\LibX\OAuth2\\Service\\' . $name;

      if(!class_exists($class))
        throw new \Exception('Service with name ' . $name . ' not found');

      return new $class($credentials, $this->client, $storage, $scopes, $baseApiUri);
    }
495751
public function process(ContainerBuilder $container)
    {
        if (!$container->has($this->stylesCollectionId)) {
            throw new \LogicException(
                sprintf(
                    'Style collection service "%s" is not defined',
                    $this->stylesCollectionId
                )
            );
        }

        $stylesCollection = $container->findDefinition($this->stylesCollectionId);

        foreach ($container->findTaggedServiceIds($this->tagName) as $serviceStyleId => $tags) {
            foreach ($tags as $tagAttributes) {
                if (!isset($tagAttributes[$this->styleNameAttribute])) {
                    throw new \LogicException(
                        sprintf(
                            'Tag "%s" of service "%s" should have an attribute "%s"',
                            $this->tagName,
                            $serviceStyleId,
                            $this->styleNameAttribute
                        )
                    );
                }
                $name = $tagAttributes['style'];
                $stylesCollection->addMethodCall('set', [$name, new Reference($serviceStyleId)]);
            }
        }
    }
1063256
private void createService(@NonNull OkHttpClient client, String baseUrl) {

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create(createGson()))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(client)
                .build();

        service = retrofit.create(RestApi.class);
    }
924761
function TransactionBuilder(apiClient) {
    
    if (typeof apiClient.namespace === "undefined" || apiClient.namespace === null) {
        throw new Error("The API client has not been initialized");
    }
    
    this.client = apiClient;
    this.records = [];
    this.keys = [];
    this.metadata = ByteBuffer.fromHex("");
}
499087
public function newApi($apiContext, AuthInterface $auth, $baseUrl = '')
    {
        $apiContext = ucfirst($apiContext);

        $class = 'Mautic\\Api\\'.$apiContext;

        if (!class_exists($class)) {
            throw new ContextNotFoundException("A context of '$apiContext' was not found.");
        }

        return new $class($auth, $baseUrl);
    }
1245466
protected static function defaultCreateApi(ContainerInterface $container, string $class): CrudInterface
    {
        static::assertClassImplements($class, CrudInterface::class);

        /** @var FactoryInterface $factory */
        $factory = $container->get(FactoryInterface::class);
        $api     = $factory->createApi($class);

        return $api;
    }
659063
private function createRequest(
        SapiInterface $sapi,
        PsrContainerInterface $container,
        callable $requestFactory
    ): ServerRequestInterface {
        // check the factory method signature
        assert(
            $this->checkPublicStaticCallable(
                $requestFactory,
                [SapiInterface::class, PsrContainerInterface::class],
                ServerRequestInterface::class
            ),
            'Factory method should have signature ' .
            '`public static methodName(SapiInterface, PsrContainerInterface): ServerRequestInterface`'
        );

        $request = call_user_func($requestFactory, $sapi, $container);

        return $request;
    }
296265
public function create()
    {
        $pluginClient = new PluginClient($this->httpClient, [
            new BaseUriPlugin($this->uriFactory->createUri($this->api_url), ['replace' => true]),
            new AuthenticationPlugin(new BasicAuth($this->api_key, '')),
            new ErrorPlugin(),
            new ContentTypePlugin(),
        ]);

        return new Client($pluginClient, $this->apiRequestFactory);
    }
877927
public function setHttpClient($httpClient): void
    {
        if (!$httpClient instanceof ClientInterface && !$httpClient instanceof HttpClient) {
            throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Psr\\Http\\Client\\ClientInterface');
        }

        $this->httpClient = $httpClient;
    }
254358
public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('ezpublish.field_type_collection.factory')) {
            return;
        }

        $fieldTypeCollectionFactoryDef = $container->getDefinition('ezpublish.field_type_collection.factory');

        // Field types.
        // Alias attribute is the field type string.
        foreach ($container->findTaggedServiceIds('ezpublish.fieldType') as $id => $attributes) {
            foreach ($attributes as $attribute) {
                if (!isset($attribute['alias'])) {
                    throw new LogicException(
                        'ezpublish.fieldType service tag needs an "alias" attribute to identify the field type. None given.'
                    );
                }

                $fieldTypeCollectionFactoryDef->addMethodCall(
                    'registerFieldType',
                    array(
                        // Only pass the service Id since field types will be lazy loaded via the service container
                        $id,
                        $attribute['alias'],
                    )
                );

                // Add FieldType to the "concrete" list if it's not a fake.
                if (!is_a($container->findDefinition($id)->getClass(), '\eZ\Publish\Core\FieldType\Null\Type', true)) {
                    $fieldTypeCollectionFactoryDef->addMethodCall(
                        'registerConcreteFieldTypeIdentifier',
                        array($attribute['alias'])
                    );
                }
            }
        }
    }
360023
public function create(ApiClientInterface $client, UserInterface $user = null)
    {
        $tokenClass = $this->tokenClass;

        return $tokenClass::create($client, $user);
    }
956842
public function process(ContainerBuilder $container)
    {
        $metaTagHandlers = $container->findTaggedServiceIds('netgen_open_graph.meta_tag_handler');
        if (!empty($metaTagHandlers) && $container->hasDefinition('netgen_open_graph.handler_registry')) {
            $handlerRegistry = $container->getDefinition('netgen_open_graph.handler_registry');
            foreach ($metaTagHandlers as $serviceId => $metaTagHandler) {
                if (!isset($metaTagHandler[0]['alias'])) {
                    throw new LogicException(
                        'netgen_open_graph.meta_tag_handler service tag needs an "alias" attribute to identify the handler. None given.'
                    );
                }
                $handlerRegistry->addMethodCall(
                    'addHandler',
                    array(
                        $metaTagHandler[0]['alias'],
                        new Reference($serviceId),
                    )
                );
            }
        }
    }
298885
protected function createClient(
        string $apiKey,
        string $spaceId,
        string $environmentId,
        ClientOptions $clientOptions
    ): ClientInterface {
        return new Client($apiKey, $spaceId, $environmentId, $clientOptions);
    }
890148
public function process(ContainerBuilder $container)
    {
        $storage = $container->getParameter('o_auth2_server.storage');

        $validator = [
            'authorization_code' => 'OAuth2\\Storage\\IAuthorizationCodeStorage',
            'access_token' => 'OAuth2\\Storage\\IAccessTokenStorage',
            'client' => 'OAuth2\\Storage\\IClientStorage',
            'refresh_token' => 'OAuth2\\Storage\\IRefreshTokenStorage',
        ];

        // validate if there is some unknown key
        $validatorKeys = array_keys($validator);
        $definedKeys = array_keys($storage);
        $diff = array_diff($definedKeys, $validatorKeys);

        if (!empty($diff)) {
            throw new InvalidConfigurationException(
                "Unrecognized storages '" . join(', ', $diff) . "'."
            );
        }

        foreach ($storage as $key => $value) {
            // all storage keys has to be strings (service names)
            if (!is_string($value)) {
                $type = gettype($value);

                throw new InvalidConfigurationException(
                    "o_auth2_server.storage.$key has to be string, $type given."
                );
            }

            // service has to exist
            if (!$container->hasDefinition($value)) {
                throw new InvalidConfigurationException(
                    "Service '$value' does not exist."
                );
            }

            // service has to implement given interface
            $service = $container->getDefinition($value);

            if (!is_subclass_of($service->getClass(), $validator[$key])) {
                throw new InvalidConfigurationException(
                    "Service '$value' does not implement {$validator[$key]}."
                );
            }

            // if is temporary generator, set lifetime from config
            if (is_subclass_of($service->getClass(), 'OAuth2\\Storage\\ITemporaryGenerator')) {
                $service->addMethodCall(
                    'setLifetime',
                    [
                        $container->getParameter("o_auth2_server.{$key}s.lifetime")
                    ]
                );
            }

            $container->setAlias("o_auth2_server.storage.$key", new Alias($value));
        }
    }