getProxy() публичный Метод

Gets proxy configuration
public getProxy ( ) : array | boolean
Результат array | boolean
Пример #1
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Service\Azure\Client\ClientInterface::prepareRequest()
  */
 public function prepareRequest($path, $method, $apiVersion, $baseUrl = Azure::URL_MANAGEMENT_WINDOWS, $queryData = [], $postFields = [], $headers = [])
 {
     if (!in_array($method, static::$httpMethods)) {
         throw new InvalidArgumentException(sprintf('Http method %s not supported or not exists.', $method));
     }
     try {
         $url = $baseUrl . $path;
         $parts = parse_url($url);
         if (isset($parts['query'])) {
             parse_str($parts['query'], $query);
         }
         if (!isset($query['api-version'])) {
             $queryData['api-version'] = $apiVersion;
         }
         $request = new Request($method, $url);
         $proxySettings = $this->azure->getProxy();
         if ($proxySettings !== false) {
             $request->setOptions(['proxyhost' => $proxySettings['host'], 'proxyport' => $proxySettings['port'], 'proxytype' => $proxySettings['type']]);
             if ($proxySettings['user']) {
                 $request->setOptions(['proxyauth' => "{$proxySettings['user']}:{$proxySettings['pass']}", 'proxyauthtype' => $proxySettings['authtype']]);
             }
         }
         $request->addQuery($queryData);
         if ($baseUrl === Azure::URL_MANAGEMENT_WINDOWS) {
             $headers['Content-Type'] = 'application/json';
         }
         if (empty($headers['Authorization']) && $baseUrl === Azure::URL_MANAGEMENT_WINDOWS) {
             $headers['Authorization'] = 'Bearer ' . $this->azure->getClientToken(Azure::URL_MANAGEMENT_WINDOWS)->token;
         }
         if (count($postFields)) {
             $request->append(json_encode($postFields));
         } else {
             if ($method == 'POST' && !isset($headers['Content-Length'])) {
                 // pecl_http does not include Content-Length for empty posts what breaks integration with Azure.
                 $headers['Content-Length'] = 1;
                 $request->append(" ");
             } else {
                 if (in_array($method, ['PUT', 'PATCH']) && !isset($headers['Content-Length'])) {
                     // pecl_http does not include Content-Length for empty posts what breaks integration with Azure.
                     $headers['Content-Length'] = 0;
                 }
             }
         }
         if (count($headers)) {
             $request->addHeaders($headers);
         }
     } catch (Exception $e) {
         throw new AzureException($e->getMessage());
     }
     return $request;
 }