1<?php 2/* 3This program is free software; you can redistribute it and/or 4modify it under the terms of the GNU General Public License 5version 2 as published by the Free Software Foundation. 6 7This program is distributed in the hope that it will be useful, 8but WITHOUT ANY WARRANTY; without even the implied warranty of 9MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10GNU General Public License for more details. 11 12You should have received a copy of the GNU General Public License along 13with this program; if not, write to the Free Software Foundation, Inc., 1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15*/ 16 17/** 18 * @dir 19 * @brief Utility functions for specific applications 20 * @file 21 * @brief Utility functions to handle curl requests 22 */ 23 24/** 25 * @namespace Fossology::Lib::Application 26 * @brief Utility functions for specific applications 27 */ 28namespace Fossology\Lib\Application; 29 30/** 31 * @class CurlRequest 32 * @brief Handle curl requests 33 */ 34class CurlRequest 35{ 36 /** 37 * @var resource $handle 38 * Resource to handle curl requests. 39 */ 40 private $handle = null; 41 42 /** 43 * Constructor to initialize curl handler with URL. 44 * @param string $url URL to initialize handler with. 45 */ 46 public function __construct($url) 47 { 48 $this->handle = curl_init($url); 49 } 50 51 /** 52 * Set curl options for the handle 53 * @param array $options Options for curl handler 54 */ 55 public function setOptions($options) 56 { 57 curl_setopt_array($this->handle, $options); 58 } 59 60 /** 61 * Execute curl request. 62 * @return bool 63 */ 64 public function execute() 65 { 66 return curl_exec($this->handle); 67 } 68 69 /** 70 * Get info from curl request. 71 * @param int $resource Required info 72 * @return mixed 73 */ 74 public function getInfo($resource) 75 { 76 return curl_getinfo($this->handle, $resource); 77 } 78 79 /** 80 * Close the curl handle. 81 */ 82 public function close() 83 { 84 curl_close($this->handle); 85 } 86} 87