1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
<?php
namespace SIW\Plato;
class Download_File extends Plato_Interface {
const TIMEOUT = 60;
protected $endpoint = 'DownloadDocumentFile';
public function download( string $identifier, string $extension = null ) {
$this->add_query_arg( 'fileIdentifier', $identifier );
$temp_file = download_url( $this->endpoint_url, self::TIMEOUT );
if ( is_wp_error( $temp_file ) ) {
return null;
}
if ( null !== $extension ) {
$temp_file_ext = "{$temp_file}.{$extension}";
rename( $temp_file, $temp_file_ext );
$temp_file = $temp_file_ext;
}
return $temp_file;
}
}