This commit is contained in:
		
							parent
							
								
									4ca5d048d9
								
							
						
					
					
						commit
						345e6a0c51
					
				| @ -64,3 +64,10 @@ Get html form | |||||||
| ```php | ```php | ||||||
| $form = $client->htmlForm(); | $form = $client->htmlForm(); | ||||||
| ``` | ``` | ||||||
|  | Rename files inside zip | ||||||
|  | ```php | ||||||
|  | $file = (new FileRequest('http://example.com/image.png')) | ||||||
|  |     ->fileOptions([ | ||||||
|  |         'name' => 'my-new-name.png' | ||||||
|  |     ]); | ||||||
|  | ``` | ||||||
|  | |||||||
| @ -6,6 +6,7 @@ class FileRequest | |||||||
| { | { | ||||||
|     private $url; |     private $url; | ||||||
|     private $fallbackUrl; |     private $fallbackUrl; | ||||||
|  |     private $fileOptions = []; | ||||||
| 
 | 
 | ||||||
|     public function __construct(string $url, string $fallbackUrl = null) |     public function __construct(string $url, string $fallbackUrl = null) | ||||||
|     { |     { | ||||||
| @ -27,6 +28,18 @@ class FileRequest | |||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public function fileOptions(array $fileOptions) | ||||||
|  |     { | ||||||
|  |         $this->fileOptions = $fileOptions; | ||||||
|  | 
 | ||||||
|  |         return $this; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function getFileOptions(): array | ||||||
|  |     { | ||||||
|  |         return $this->fileOptions; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public function getUrl(): string |     public function getUrl(): string | ||||||
|     { |     { | ||||||
|         return $this->url; |         return $this->url; | ||||||
| @ -39,9 +52,10 @@ class FileRequest | |||||||
| 
 | 
 | ||||||
|     public function toArray(): array |     public function toArray(): array | ||||||
|     { |     { | ||||||
|         return [ |         return array_filter([ | ||||||
|             'url' => $this->url, |             'url' => $this->url, | ||||||
|             'fallback_url' => $this->fallbackUrl, |             'fallbackUrl' => $this->fallbackUrl, | ||||||
|         ]; |             'fileOptions' => $this->fileOptions, | ||||||
|  |         ]); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -15,9 +15,10 @@ class MultiDownloaderClientTest extends TestCase | |||||||
| 
 | 
 | ||||||
|     private function testFiles() |     private function testFiles() | ||||||
|     { |     { | ||||||
|         return array_map(function ($url) { |         return array_map(function ($url, $i) { | ||||||
|             return new FileRequest($url); |             return (new FileRequest($url)) | ||||||
|         }, $this->testFiles); |                 ->fileOptions(['name' => 'test' . $i . '.png']); | ||||||
|  |         }, $this->testFiles, array_keys($this->testFiles)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function testDownloadAsString() |     public function testDownloadAsString() | ||||||
| @ -30,14 +31,14 @@ class MultiDownloaderClientTest extends TestCase | |||||||
| 
 | 
 | ||||||
|         $md5 = md5($response); |         $md5 = md5($response); | ||||||
| 
 | 
 | ||||||
|         $this->assertEquals('ea9726d2ecbe6b820899ba125bf0ae94', $md5); |         $this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $md5); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function testDownloadTo() |     public function testDownloadTo() | ||||||
|     { |     { | ||||||
|         $client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']); |         $client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']); | ||||||
| 
 | 
 | ||||||
|         $path = sys_get_temp_dir() . '/testDownloadTo.zip'; |         $path = __DIR__  . '/testDownloadTo.zip'; | ||||||
| 
 | 
 | ||||||
|         $client->setFiles($this->testFiles()); |         $client->setFiles($this->testFiles()); | ||||||
|         $client->downloadTo($path); |         $client->downloadTo($path); | ||||||
| @ -45,7 +46,7 @@ class MultiDownloaderClientTest extends TestCase | |||||||
|         $md5 = md5_file($path); |         $md5 = md5_file($path); | ||||||
| 
 | 
 | ||||||
|         $this->assertFileExists($path); |         $this->assertFileExists($path); | ||||||
|         $this->assertEquals('ea9726d2ecbe6b820899ba125bf0ae94', $md5); |         $this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $md5); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function testForm() |     public function testForm() | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								tests/testDownloadTo.zip
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tests/testDownloadTo.zip
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user