From e9e003435709e06d7acb13cc141f7c972f889c98 Mon Sep 17 00:00:00 2001 From: Aimeos Date: Sun, 6 Mar 2022 10:12:48 +0100 Subject: [PATCH] Added optional local file path to readf() --- src/Base/Filesystem/Laravel.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Base/Filesystem/Laravel.php b/src/Base/Filesystem/Laravel.php index 41638f7..21e58a2 100644 --- a/src/Base/Filesystem/Laravel.php +++ b/src/Base/Filesystem/Laravel.php @@ -194,20 +194,21 @@ public function read( string $path ) : string * Reads the content of the remote file and writes it to a local one * * @param string $path Path to the remote file + * @param string|null $local Path to the local file (optional) * @return string Path of the local file * @throws \Aimeos\Base\Filesystem\Exception If an error occurs */ - public function readf( string $path ) : string + public function readf( string $path, string $local = null ) : string { - if( ( $filename = tempnam( $this->tempdir, 'ai-' ) ) === false ) { + if( $local === null && ( $local = @tempnam( $this->tempdir, 'ai-' ) ) === false ) { throw new Exception( sprintf( 'Unable to create file in "%1$s"', $this->tempdir ) ); } - if( @file_put_contents( $filename, $this->fs->get( $path ) ) === false ) { - throw new Exception( sprintf( 'Couldn\'t write file "%1$s"', $filename ) ); + if( @file_put_contents( $local, $this->fs->get( $path ) ) === false ) { + throw new Exception( sprintf( 'Couldn\'t write file "%1$s"', $local ) ); } - return $filename; + return $local; }