1818 *
1919 * @author Justin Bishop <jubishop@gmail.com>
2020 * @author Anthon Pang <apang@softwaredevelopment.ca>
21+ * @author Fabrizio Branca <mail@fabrizio-branca.de>
2122 */
2223
2324namespace WebDriver \Service ;
@@ -36,30 +37,41 @@ class CurlService implements CurlServiceInterface
3637 */
3738 public function execute ($ requestMethod , $ url , $ parameters = null , $ extraOptions = array ())
3839 {
39- $ customHeaders = array (
40+ $ customHeaders = array (
4041 'Content-Type: application/json;charset=UTF-8 ' ,
4142 'Accept: application/json;charset=UTF-8 ' ,
4243 );
4344
4445 $ curl = curl_init ($ url );
4546 curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
4647
47- if ($ requestMethod === 'POST ' ) {
48- curl_setopt ($ curl , CURLOPT_POST , true );
49- if ($ parameters && is_array ($ parameters )) {
50- curl_setopt ($ curl , CURLOPT_POSTFIELDS , json_encode ($ parameters ));
51- } else {
52- $ customHeaders [] = 'Content-Length: 0 ' ;
53- }
54- } else if ($ requestMethod == 'DELETE ' ) {
55- curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , 'DELETE ' );
56- } else if ($ requestMethod == 'PUT ' ) {
57- curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , 'PUT ' );
58- if ($ parameters && is_array ($ parameters )) {
59- curl_setopt ($ curl , CURLOPT_POSTFIELDS , json_encode ($ parameters ));
60- } else {
61- $ customHeaders [] = 'Content-Length: 0 ' ;
62- }
48+ switch ($ requestMethod ) {
49+ case 'GET ' :
50+ break ;
51+
52+ case 'POST ' :
53+ if ($ parameters && is_array ($ parameters )) {
54+ curl_setopt ($ curl , CURLOPT_POSTFIELDS , json_encode ($ parameters ));
55+ } else {
56+ $ customHeaders [] = 'Content-Length: 0 ' ;
57+ }
58+
59+ curl_setopt ($ curl , CURLOPT_POST , true );
60+ break ;
61+
62+ case 'DELETE ' :
63+ curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , 'DELETE ' );
64+ break ;
65+
66+ case 'PUT ' :
67+ if ($ parameters && is_array ($ parameters )) {
68+ curl_setopt ($ curl , CURLOPT_POSTFIELDS , json_encode ($ parameters ));
69+ } else {
70+ $ customHeaders [] = 'Content-Length: 0 ' ;
71+ }
72+
73+ curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , 'PUT ' );
74+ break ;
6375 }
6476
6577 foreach ($ extraOptions as $ option => $ value ) {
0 commit comments