youngguns-nl / moneybird_php_api

A PHP Library for the MoneyBird API
http://www.moneybird.nl
MIT License
37 stars 14 forks source link

MoneybirdApi::$sslInsecure werkt niet #4

Closed jhogervorst closed 14 years ago

jhogervorst commented 14 years ago

Probleem: Indien MoneybirdApi::$sslInsecure op true staat, werkt niks meer.

Oorzaak: Om de cURL-instellingen voor de $sslInsecure mee te geven, wordt array_merge() gebruikt. Het punt is echter dat alle keys integers zijn en om die reden begint array_merge() vanaf 0 te tellen en worden de oude keys vergeten.

Relevante code: \ Api.php, regel 123 t/m 161. <?php / * Connect with API * @throws MoneybirdConnectionErrorException * @access protected / protected function initConnection($username, $password) { if (!$this->connection = curl_init()) { throw new MoneybirdConnectionErrorException('Unable to connect to Moneybird Api'); } else { $options = array( CURLOPT_USERPWD => $username.':'.$password, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array( 'Content-Type: application/xml', 'Accept: application/xml' ), );

        if (self::$sslInsecure) {
            $options = array_merge($options, array(
                CURLOPT_SSL_VERIFYHOST => false,
                CURLOPT_SSL_VERIFYPEER => false,
            ));
        }

        $setopt = curl_setopt_array($this->connection, $options);
        if (!$setopt)
        {
            throw new MoneybirdConnectionErrorException('Unable to set cURL options'.PHP_EOL.curl_error($this->connection));
        }
    }
}
?>

Gefixte code <?php /* * Connect with API * @throws MoneybirdConnectionErrorException * @access protected */ protected function initConnection($username, $password) { if (!$this->connection = curl_init()) { throw new MoneybirdConnectionErrorException('Unable to connect to Moneybird Api'); } else { $options = array( CURLOPT_USERPWD => $username.':'.$password, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array( 'Content-Type: application/xml', 'Accept: application/xml' ), );

        if (self::$sslInsecure) {
            $options[CURLOPT_SSL_VERIFYHOST] = false;
            $options[CURLOPT_SSL_VERIFYPEER] = false;
        }

        $setopt = curl_setopt_array($this->connection, $options);
        if (!$setopt)
        {
            throw new MoneybirdConnectionErrorException('Unable to set cURL options'.PHP_EOL.curl_error($this->connection));
        }
    }
}
?>
pluijm commented 14 years ago

bedankt, heb het verwerkt