Overview
  • Package
  • Class

Packages

  • Klarna
    • Checkout
  • Payment
    • Klarna
      • HTTP
      • Interfaces
      • Unit
        • Tests

Classes

  • Klarna_Checkout_HTTP_CURLFactory
  • Klarna_Checkout_HTTP_Transport
  1 <?php
  2 /**
  3  * Copyright 2015 Klarna AB
  4  *
  5  * Licensed under the Apache License, Version 2.0 (the "License");
  6  * you may not use this file except in compliance with the License.
  7  * You may obtain a copy of the License at
  8  *
  9  *     http://www.apache.org/licenses/LICENSE-2.0
 10  *
 11  * Unless required by applicable law or agreed to in writing, software
 12  * distributed under the License is distributed on an "AS IS" BASIS,
 13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  * See the License for the specific language governing permissions and
 15  * limitations under the License.
 16  *
 17  * File containing the Klarna_Checkout_HTTP_CURLHeaders class
 18  *
 19  * PHP version 5.3
 20  *
 21  * @category   Payment
 22  * @package    Payment_Klarna
 23  * @subpackage HTTP
 24  * @author     Klarna <support@klarna.com>
 25  * @copyright  2015 Klarna AB
 26  * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
 27  * @link       http://developers.klarna.com/
 28  */
 29 
 30 /**
 31  * A wrapper around the cURL functions
 32  *
 33  * @category   Payment
 34  * @package    Payment_Klarna
 35  * @subpackage HTTP
 36  * @author     David K. <david.keijser@klarna.com>
 37  * @copyright  2015 Klarna AB
 38  * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
 39  * @link       http://developers.klarna.com/
 40  */
 41 class Klarna_Checkout_HTTP_CURLHandle implements
 42     Klarna_Checkout_HTTP_CURLHandleInterface
 43 {
 44     /**
 45      * Handle for cURL.
 46      *
 47      * @var resource
 48      */
 49     private $_handle = null;
 50 
 51     /**
 52      * Create a new cURL handle
 53      */
 54     public function __construct()
 55     {
 56         if (!extension_loaded('curl')) {
 57             throw new RuntimeException(
 58                 'cURL extension is requred.'
 59             );
 60         }
 61         $this->_handle = curl_init();
 62     }
 63 
 64     /**
 65      * Set an option for the cURL transfer
 66      *
 67      * @param int   $name  option the set
 68      * @param mixed $value the value to be set on option
 69      *
 70      * @return void
 71      */
 72     public function setOption($name, $value)
 73     {
 74         curl_setopt($this->_handle, $name, $value);
 75     }
 76 
 77     /**
 78      * Perform the cURL session
 79      *
 80      * @return mixed response
 81      */
 82     public function execute()
 83     {
 84         return curl_exec($this->_handle);
 85     }
 86 
 87     /**
 88      * Get information regarding this transfer
 89      *
 90      * @return array
 91      */
 92     public function getInfo()
 93     {
 94         return curl_getinfo($this->_handle);
 95     }
 96 
 97     /**
 98      * Get error message regarding this transfer
 99      *
100      * @return string Error message
101      */
102     public function getError()
103     {
104         return curl_error($this->_handle);
105     }
106 
107     /**
108      * Close the cURL session
109      *
110      * @return void
111      */
112     public function close()
113     {
114         curl_close($this->_handle);
115     }
116 }
117 
API documentation generated by ApiGen