瀏覽代碼

Enable Proxy feature

Bhavik Shah 7 年之前
父節點
當前提交
69c9f77efd
共有 1 個文件被更改,包括 46 次插入0 次删除
  1. 46 0
      src/Builder.php

+ 46 - 0
src/Builder.php

@@ -284,6 +284,52 @@ class Builder {
             ->withOption( 'VERBOSE', true );
     }
 
+    /**
+     * Enable Proxy for the cURL request
+     *
+     * @param   string $proxy    Proxy hostname
+     * @return Builder
+     */
+    public function enableProxy($proxy)
+    {
+        return $this->withPackageOption( 'enableProxy', true )
+            ->withOption( 'PROXY', $proxy );
+    }
+
+    /**
+     * Allow User to specify Proxy port seperately. It will work only if Proxy
+     * is enabled using `enableProxy` method.
+     *
+     * @param   int $proxyPort     Proxy port
+     * @return Builder
+     */
+    public function withProxyPort($proxyPort)
+    {
+        if ( $this->packageOptions[ 'enableProxy' ] ) {
+            $this->withOption( 'PROXYPORT', $proxyPort );
+        }
+
+        return $this;
+    }
+
+    /**
+     * Allow User to specify Proxy authentication credentials. It will add
+     * authentication credentials only if Proxy is enabled using `enableProxy`
+     * method.
+     *
+     * @param   string $proxyUsername     Proxy Authentication Username
+     * @param   string $proxyPassword     Proxy Authentication Password
+     * @return Builder
+     */
+    public function withProxyAuth($proxyUsername, $proxyPassword)
+    {
+        if ( $this->packageOptions[ 'enableProxy' ] ) {
+            $this->withOption( 'PROXYUSERPWD', $proxyUsername . ':' . $proxyPassword );
+        }
+
+        return $this;
+    }
+
     /**
      * Enable File sending
      *