Create Connection to the Google Server
@param $endpoint
@throws Exception\EndpointServerException
515349
private function createConnection($endpoint)
    {
        // port
        $port = $this->getOption('ssl') == true ? 443 : 80;

        if (!($connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
            $errorcode = socket_last_error();
            $errormsg = socket_strerror($errorcode);
            throw new Exception\EndpointServerException('Analytics Socket failure! Error: ' . $errormsg);
        }

        if (!socket_connect($connection, $endpoint['host'], $port)) {
            $errorcode = socket_last_error();
            $errormsg = socket_strerror($errorcode);
            throw new Exception\EndpointServerException('Analytics Host not reachable! Error: ' . $errormsg);
        }

        socket_set_option($connection, SOL_SOCKET, SO_RCVTIMEO, array('sec' => self::READ_TIMEOUT, 'usec' => 0));

        if ($this->getOption('async')) {
            socket_set_nonblock($connection);
        }

        $this->connection = $connection;
    }
82018
public function getEndpoint($endpoint)
    {
        // Get Endpoint Class name
        $endpoint = studly_case($endpoint);

        if (!array_key_exists($endpoint, $this->endpoints)) {
            throw new InvalidEndpointException("Endpoint {$endpoint} does not exists");
        }

        $class = $this->endpoints[$endpoint];

        // Check if an instance has already been initiated
        if (isset($this->cachedEndpoints[$endpoint]) === false) {
            // check if class is an EndPoint
            $endpointClass = new \ReflectionClass($class);
            if (!$endpointClass->isSubclassOf('Atog\Api\Endpoint')) {
                throw new InvalidEndpointException("Class {$class} does not extend Atog\\Api\\Endpoint");
            }
            
            // check for model
            $model = new Model();
            if (array_key_exists('models', $this->config) && array_key_exists($endpoint, $this->config['models'])) {
                $modelClass = $this->config['models'][$endpoint];
                if (class_exists($modelClass)) {
                    $model = new $modelClass();
                }
            }
            $this->cachedEndpoints[$endpoint] = new $class($this, $model);
        }
        
        return $this->cachedEndpoints[$endpoint];
    }
1373913
private function createConnection(Endpoint $endpoint, DefinitionInterface $node): ObjectDefinition
    {
        $connection = new ObjectDefinition();
        $connection->setName("{$node->getName()}Connection");

        if (!$endpoint->hasType($connection->getName())) {
            $endpoint->addType($connection);

            $totalCount = new FieldDefinition();
            $totalCount->setName('totalCount');
            $totalCount->setType('Int');
            $totalCount->setNonNull(true);
            $connection->addField($totalCount);

            $pages = new FieldDefinition();
            $pages->setName('pages');
            $pages->setType('Int');
            $pages->setNonNull(true);
            $connection->addField($pages);

            $pageInfo = new FieldDefinition();
            $pageInfo->setName('pageInfo');
            $pageInfo->setType('PageInfo');
            $pageInfo->setNonNull(true);
            $connection->addField($pageInfo);

            $edgeObject = new ObjectDefinition();
            $edgeObject->setName("{$node->getName()}Edge");
            if (!$endpoint->hasType($edgeObject->getName())) {
                $endpoint->addType($edgeObject);

                $nodeField = new FieldDefinition();
                $nodeField->setName('node');
                $nodeField->setType($node->getName());
                $nodeField->setNonNull(true);
                $edgeObject->addField($nodeField);

                $cursor = new FieldDefinition();
                $cursor->setName('cursor');
                $cursor->setType('string');
                $cursor->setNonNull(true);
                $edgeObject->addField($cursor);
            }

            $edges = new FieldDefinition();
            $edges->setName('edges');
            $edges->setType($edgeObject->getName());
            $edges->setList(true);
            $connection->addField($edges);
        } else {
            $connection = $endpoint->getType($connection->getName());
        }

        return $connection;
    }
511288
public function createSavepoint($savepoint)
    {
        if (! $this->getDatabasePlatform()->supportsSavepoints()) {
            throw ConnectionException::savepointsNotSupported();
        }

        $this->getWrappedConnection()->exec($this->platform->createSavePoint($savepoint));
    }
733269
protected function createClient($endpoint, $config = [])
    {
        $ssl = $this->config['ssl'];
        $name = $this->config['ssl_name'];
        $verifySign = $this->config['ssl_verify_sign'];
        $verifyPeer = $this->config['ssl_verify_peer'];
        $verifyDepth = $this->config['ssl_verify_depth'];

        $context = [];
        $context['socket'] = [
            'connect' => $endpoint
        ];
        $context['ssl'] = [
            'capture_peer_cert' => true,
            'capture_peer_chain' => true,
            'capture_peer_cert_chain' => true,
            'allow_self_signed' => !$verifySign,
            'verify_peer' => $verifyPeer,
            'verify_peer_name' => $verifyPeer,
            'verify_depth' => $verifyDepth,
            'SNI_enabled' => $name !== '',
            'SNI_server_name' => $name,
            'peer_name' => $name,
            'disable_compression' => true,
            'honor_cipher_order' => true,
        ];

        if ($ssl && isset($config['ssl_cafile']))
        {
            $context['ssl']['cafile'] = $config['ssl_cafile'];
        }

        if ($ssl && isset($config['ssl_capath']))
        {
            $context['ssl']['capath'] = $config['ssl_capath'];
        }

        $context = stream_context_create($context);
        // Error reporting suppressed since stream_socket_client() emits an E_WARNING on failure.
        $socket = @stream_socket_client(
            $endpoint,
            $errno,
            $errstr,
            0, // Timeout does not apply for async connect.
            STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT,
            $context
        );

        if (!$socket || $errno > 0)
        {
            throw new LogicException(
                sprintf('Could not connect socket [%s] because of error [%d; %s]', $endpoint, $errno, $errstr)
            );
        }

        stream_set_blocking($socket, false);

        return $socket;
    }
508673
public function add_endpoints( $git, $endpoint ) {
		switch ( $git::$method ) {
			case 'projects':
				$endpoint = add_query_arg( 'per_page', '100', $endpoint );
				break;
			case 'meta':
			case 'tags':
			case 'branches':
			case 'download_link':
				break;
			case 'file':
			case 'changes':
			case 'readme':
				$endpoint = add_query_arg( 'ref', $git->type->branch, $endpoint );
				break;
			case 'translation':
				$endpoint = add_query_arg( 'ref', 'master', $endpoint );
				break;
			case 'release_asset':
				$endpoint = add_query_arg( 'job', $git->type->ci_job, $endpoint );
				break;
			default:
				break;
		}

		$endpoint = $this->add_access_token_endpoint( $git, $endpoint );

		/*
		 * If GitLab CE/Enterprise return this endpoint.
		 */
		if ( ! empty( $git->type->enterprise_api ) ) {
			return $git->type->enterprise_api . $endpoint;
		}

		return $endpoint;
	}
158569
protected function createEndpoint(string $name, array $args) : EndpointInterface {
        $className = $this->getEndpointClassName($name);

        // aditional parameters
        $args[] = $this->authentication;
        $args[] = $this->client;
        $args[] = $this->throwsExceptions;
        $args[] = $this->baseUrl;

        return new $className(...$args);
    }
634827
public function api($endpoint, array $params = [], $method = Method::GET)
    {
        $headers = $this->getApiHeaders();
        $options = $this->prepareOptions($params, $method);
        Method::isMethodSupported($method);
        if ($this->isUsingTokenParam()) {
            $params['oauth2_access_token'] = $this->accessToken->getToken();
        } else {
            $headers['Authorization'] = 'Bearer ' . $this->accessToken->getToken();
        }
        $guzzle = new GuzzleClient([
            'base_uri' => $this->getApiRoot(),
            'headers' => $headers,
        ]);
        if (!empty($params) && Method::GET === $method) {
            $endpoint .= '?' . build_query($params);
        }
        try {
            $response = $guzzle->request($method, $endpoint, $options);
        } catch (RequestException $requestException) {
            throw Exception::fromRequestException($requestException);
        }
        return self::responseToArray($response);
    }
1105268
protected function executeQuery($endpoint)
    {
        $ch = curl_init($endpoint);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $responseContent = curl_exec($ch);
        $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        if ($responseContent === false || $httpStatus != 200) {
            throw new MoneyException('Could not execute YahooFinanceRatioProvider query to endpoint '.$endpoint);
        }

        curl_close($ch);

        return $responseContent;
    }
923433
protected function buildRequestUrl($endpoint, $params = null)
    {
        if($this->user == null)
            throw new Exception("Please authenticate user first!");

        $requestPath = $this->requestPath . $endpoint . ".json". $this->getParams( $params );

        return $requestPath;
    }
497963
public function setEndPoint($endPoint)
    {
        if (strlen($this->getEndPointGroup()) > 0)
        {
            throw new RuntimeException(
                "End point group has been already set. You can set either end point or end point group."
            );
        }

        $this->endPoint = (int) $endPoint;

        return $this;
    }
716088
public function get($endpoint, $params = [])
    {
        // build url
        $url = $this->domain . '/' . $endpoint;

        if (!empty($params)) {
            $url = $url . '?' . http_build_query($params);
        }

        $request = new Request($url);
        
        // Add client secret header
        if (isset($this->config['secret'])) {
            $request->headers->add(['X-Client-Secret' => $this->config['secret']]);
        }
        
        // add curl options
        if (isset($this->config['curl']) && is_array($this->config['curl'])) {
            foreach ($this->config['curl'] as $option => $value) {
                $request->setOption($option, $value);
            }
        }
        
        $request->execute();

        return $request->getResponse();
    }
1175024
public function requestEndpoint(AbstractEndpoint $endpoint)
    {
        $cloned = clone $endpoint;
        $cloned->setType($this->getName());

        return $this->getIndex()->requestEndpoint($cloned);
    }
736470
private function getURL($endpoint = null)
    {
        if (is_null($endpoint)) {
            $endpoint = $this->getEndpoint();
        } else {
            $endpoint = '/api/' . $endpoint;
        }

        return $this->config['url'] . $endpoint;
    }
306621
public function add_endpoints( $git, $endpoint ) {
		switch ( self::$method ) {
			case 'meta':
			case 'translation':
			case 'branches':
				break;
			case 'file':
			case 'readme':
				$endpoint = add_query_arg( 'at', $git->type->branch, $endpoint );
				break;
			case 'changes':
				$endpoint = add_query_arg(
					[
						'at'  => $git->type->branch,
						'raw' => '',
					],
					$endpoint
				);
				break;
			case 'tags':
			case 'download_link':
				/*
				 * Add a prefix query argument to create a subdirectory with the same name
				 * as the repo, e.g. 'my-repo' becomes 'my-repo/'
				 * Required for using stash-archive.
				 */
				$defaults = [
					'prefix' => $git->type->slug . '/',
					'at'     => $git->type->branch,
					'format' => 'zip',
				];
				$endpoint = add_query_arg( $defaults, $endpoint );
				if ( ! empty( $git->type->tags ) ) {
					$endpoint = urldecode( add_query_arg( 'at', $git->type->newest_tag, $endpoint ) );
				}
				break;
			default:
				break;
		}

		return $endpoint;
	}
920199
private function getEndpoint(string $endpoint) : string
    {
        return sprintf(
            '%s/%s/%s',
            $this->config->get('serverUrl'),
            $this->config->get('apmVersion'),
            $endpoint
        );
    }
907306
private static function curl(string $endpoint)
    {
        // Get the base URL and App Key.
        $baseUrl = self::$_baseUrl;

        // Create a cURL session.
        $curl = curl_init();

        // Set the options necessary for communicating with the UCRM Server.
        curl_setopt($curl, CURLOPT_URL, $baseUrl.$endpoint);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, false);

        // TODO: Determine if we EVER need to use HTTPS and how to handle it correctly here!
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // DEFAULT
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1); // DEFAULT

        // Set the necessary HTTP HEADERS.
        curl_setopt($curl, CURLOPT_HTTPHEADER, self::$_headers);

        return $curl;
    }