<?php
namespace ALPCAL\Util;
/**
 * Renames files safely for local storage, replacing URL characters
 * REQUIRES:
 * 	$currentName - name of the incoming, either the nonsafe or safe version
 * NOTE: Exceptions with value 22 should be caught by the calendar as a retrieve error instead of general
 */

Class GetRemoteFile
{
	public $url;
	
	public function get($method='curl')
	{
		if (!$this->url) { throw new \Exception('Util\GetRemoteFile was not supplied a url.'); }
		switch ($method)
		{
			case 'curl':
				return $this->get_curl();
				break;
			
			default:
				throw new \Exception('Util\GetRemoteFile was not supplied method type.');
		}
			
	}
	
	public function set_url($url)
	{
		$this->url = $url;
	}
	
	public function get_curl()
	{
		$curl = curl_init($this->url);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
		$curl_response = curl_exec($curl);
		if (curl_error($c))	{ throw new \Exception(curl_error($c),22);	}
		curl_close($curl);
		return $curl_response;
	}
	


}



