Completed
Branch master (e874e7)
by smiley
05:21
created

RequestTrait::fetch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
/**
3
 * Trait RequestTrait
4
 *
5
 * @filesource   RequestTrait.php
6
 * @created      13.02.2016
7
 * @package      chillerlan\TinyCurl
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2016 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\TinyCurl;
14
15
/**
16
 *
17
 */
18
trait RequestTrait{
19
20
	/**
21
	 * Path to the CA cert file
22
	 *
23
	 * @link http://init.haxx.se/ca/cacert.pem
24
	 * @var string
25
	 */
26
	protected $ca_info;
27
28
	/**
29
	 * Embed stuff from anywhere!
30
	 *
31
	 * @param string $url
32
	 * @param array  $params
33
	 * @param array  $curl_options
34
	 *
35
	 * @return \chillerlan\TinyCurl\Response
36
	 * @throws \chillerlan\TinyCurl\RequestException
37
	 */
38
	protected function fetch($url, array $params = [], array $curl_options = []){
39
		$requestOptions               = new RequestOptions;
40
		$requestOptions->curl_options = $curl_options;
41
		$requestOptions->ca_info      = $this->ca_info;
42
43
		return (new Request($requestOptions))->fetch(new URL($url, $params));
44
	}
45
46
	/**
47
	 * Sets the path to the CA cert file
48
	 *
49
	 * @param $ca_info
50
	 *
51
	 * @return $this
52
	 */
53
	protected function setRequestCA($ca_info){
54
		$this->ca_info = $ca_info;
55
56
		return $this;
57
	}
58
59
}
60