@@ -13,6 +13,11 @@ class Youtube
13
13
*/
14
14
protected $ youtube_key ; //pass in by constructor
15
15
16
+ /**
17
+ * @var string
18
+ */
19
+ protected $ referer ;
20
+
16
21
/**
17
22
* @var array
18
23
*/
@@ -28,7 +33,7 @@ class Youtube
28
33
/**
29
34
* @var array
30
35
*/
31
- var $ page_info = array ();
36
+ public $ page_info = array ();
32
37
33
38
/**
34
39
* Constructor
@@ -37,12 +42,19 @@ class Youtube
37
42
* @param array $params
38
43
* @throws \Exception
39
44
*/
40
- public function __construct ($ params )
45
+ public function __construct ($ params = array () )
41
46
{
42
- if (is_array ($ params ) && array_key_exists ('key ' , $ params )) {
43
- $ this ->youtube_key = $ params ['key ' ];
44
- } else {
45
- throw new \Exception ('Google API key is Required, please visit http://code.google.com/apis/console ' );
47
+ if (!is_array ($ params )) {
48
+ throw new \InvalidArgumentException ('The configuration options must be an array. ' );
49
+ }
50
+
51
+ if (!array_key_exists ('key ' , $ params )) {
52
+ throw new \InvalidArgumentException ('Google API key is required, please visit http://code.google.com/apis/console ' );
53
+ }
54
+ $ this ->youtube_key = $ params ['key ' ];
55
+
56
+ if (array_key_exists ('referer ' , $ params )) {
57
+ $ this ->referer = $ params ['referer ' ];
46
58
}
47
59
}
48
60
@@ -454,6 +466,9 @@ public function api_get($url, $params)
454
466
} else {
455
467
curl_setopt ($ tuCurl , CURLOPT_PORT , 443 );
456
468
}
469
+ if ($ this ->referer !== null ) {
470
+ curl_setopt ($ tuCurl , CURLOPT_REFERER , $ this ->referer );
471
+ }
457
472
curl_setopt ($ tuCurl , CURLOPT_RETURNTRANSFER , 1 );
458
473
$ tuData = curl_exec ($ tuCurl );
459
474
if (curl_errno ($ tuCurl )) {
0 commit comments