Changeset View
Changeset View
Standalone View
Standalone View
src/app/Utils.php
Show All 19 Lines | class Utils | ||||
{ | { | ||||
$start = new Carbon('first day of last month'); | $start = new Carbon('first day of last month'); | ||||
$end = new Carbon('last day of last month'); | $end = new Carbon('last day of last month'); | ||||
return $start->diffInDays($end) + 1; | return $start->diffInDays($end) + 1; | ||||
} | } | ||||
/** | /** | ||||
* Download a file from the interwebz and store it locally. | |||||
* | |||||
* @param string $source The source location | |||||
* @param string $target The target location | |||||
* @param bool $force Force the download (and overwrite target) | |||||
* | |||||
* @return void | |||||
*/ | |||||
public static function downloadFile($source, $target, $force = false) | |||||
{ | |||||
if (is_file($target) && !$force) { | |||||
return; | |||||
} | |||||
\Log::info("Retrieving {$source}"); | |||||
$fp = fopen($target, 'w'); | |||||
$curl = curl_init(); | |||||
curl_setopt($curl, CURLOPT_URL, $source); | |||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |||||
curl_setopt($curl, CURLOPT_FILE, $fp); | |||||
curl_exec($curl); | |||||
if (curl_errno($curl)) { | |||||
\Log::error("Request error on {$source}: " . curl_error($curl)); | |||||
curl_close($curl); | |||||
fclose($fp); | |||||
unlink($target); | |||||
return; | |||||
} | |||||
curl_close($curl); | |||||
fclose($fp); | |||||
} | |||||
/** | |||||
* Provide all unique combinations of elements in $input, with order and duplicates irrelevant. | * Provide all unique combinations of elements in $input, with order and duplicates irrelevant. | ||||
* | * | ||||
* @param array $input The input array of elements. | * @param array $input The input array of elements. | ||||
* | * | ||||
* @return array[] | * @return array[] | ||||
*/ | */ | ||||
public static function powerSet(array $input): array | public static function powerSet(array $input): array | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |