@@ -13,6 +13,11 @@ class Youtube
1313 */
1414 protected $ youtube_key ; //pass in by constructor
1515
16+ /**
17+ * @var string
18+ */
19+ protected $ referer ;
20+
1621 /**
1722 * @var array
1823 */
@@ -28,7 +33,7 @@ class Youtube
2833 /**
2934 * @var array
3035 */
31- var $ page_info = array ();
36+ public $ page_info = array ();
3237
3338 /**
3439 * Constructor
@@ -37,12 +42,19 @@ class Youtube
3742 * @param array $params
3843 * @throws \Exception
3944 */
40- public function __construct ($ params )
45+ public function __construct ($ params = array () )
4146 {
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 ' ];
4658 }
4759 }
4860
@@ -454,6 +466,9 @@ public function api_get($url, $params)
454466 } else {
455467 curl_setopt ($ tuCurl , CURLOPT_PORT , 443 );
456468 }
469+ if ($ this ->referer !== null ) {
470+ curl_setopt ($ tuCurl , CURLOPT_REFERER , $ this ->referer );
471+ }
457472 curl_setopt ($ tuCurl , CURLOPT_RETURNTRANSFER , 1 );
458473 $ tuData = curl_exec ($ tuCurl );
459474 if (curl_errno ($ tuCurl )) {
0 commit comments