This commit is contained in:
		
							parent
							
								
									bd500406d3
								
							
						
					
					
						commit
						e389e72844
					
				| @ -66,8 +66,6 @@ $form = $client->htmlForm(); | |||||||
| ``` | ``` | ||||||
| Rename files inside zip | Rename files inside zip | ||||||
| ```php | ```php | ||||||
| $file = (new FileRequest('http://example.com/image.png')) | $file = new FileRequest('http://example.com/image.png'); | ||||||
|     ->fileOptions([ | $file->getFileOptions()->name('new-name.png'); | ||||||
|         'name' => 'my-new-name.png' |  | ||||||
|     ]); |  | ||||||
| ``` | ``` | ||||||
|  | |||||||
							
								
								
									
										30
									
								
								src/FileOptions.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/FileOptions.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | |||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace Nwb\MultiDownloaderClient; | ||||||
|  | 
 | ||||||
|  | class FileOptions | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     private $name; | ||||||
|  | 
 | ||||||
|  |     public function name(string $name) | ||||||
|  |     { | ||||||
|  |         $this->name = $name; | ||||||
|  | 
 | ||||||
|  |         return $this; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function getName(): string | ||||||
|  |     { | ||||||
|  |         return $this->name; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function toArray(): array | ||||||
|  |     { | ||||||
|  |         return [ | ||||||
|  |             'name' => $this->name | ||||||
|  |         ]; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -4,14 +4,25 @@ namespace Nwb\MultiDownloaderClient; | |||||||
| 
 | 
 | ||||||
| class FileRequest | class FileRequest | ||||||
| { | { | ||||||
|  |     /** | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|     private $url; |     private $url; | ||||||
|  |     /** | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|     private $fallbackUrl; |     private $fallbackUrl; | ||||||
|     private $fileOptions = []; |     /** | ||||||
|  |      * @var FileOptions | ||||||
|  |      */ | ||||||
|  |     private $fileOptions; | ||||||
| 
 | 
 | ||||||
|     public function __construct(string $url, string $fallbackUrl = null) |     public function __construct(string $url, string $fallbackUrl = null) | ||||||
|     { |     { | ||||||
|         $this->url = $url; |         $this->url = $url; | ||||||
|         $this->fallbackUrl = $fallbackUrl; |         $this->fallbackUrl = $fallbackUrl; | ||||||
|  | 
 | ||||||
|  |         $this->fileOptions = new FileOptions(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function url(string $url) |     public function url(string $url) | ||||||
| @ -28,14 +39,14 @@ class FileRequest | |||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function fileOptions(array $fileOptions) |     public function fileOptions(FileOptions $fileOptions) | ||||||
|     { |     { | ||||||
|         $this->fileOptions = $fileOptions; |         $this->fileOptions = $fileOptions; | ||||||
| 
 | 
 | ||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function getFileOptions(): array |     public function getFileOptions(): FileOptions | ||||||
|     { |     { | ||||||
|         return $this->fileOptions; |         return $this->fileOptions; | ||||||
|     } |     } | ||||||
| @ -55,7 +66,7 @@ class FileRequest | |||||||
|         return array_filter([ |         return array_filter([ | ||||||
|             'url' => $this->url, |             'url' => $this->url, | ||||||
|             'fallbackUrl' => $this->fallbackUrl, |             'fallbackUrl' => $this->fallbackUrl, | ||||||
|             'fileOptions' => $this->fileOptions, |             'fileOptions' => $this->fileOptions->toArray(), | ||||||
|         ]); |         ]); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -23,15 +23,19 @@ class MultiDownloaderClient | |||||||
|     public function __construct(array $options = []) |     public function __construct(array $options = []) | ||||||
|     { |     { | ||||||
|         $apiKey = $options['apiKey'] ?? getenv('MULTI_DOWNLOADER_ACCESS_KEY'); |         $apiKey = $options['apiKey'] ?? getenv('MULTI_DOWNLOADER_ACCESS_KEY'); | ||||||
|  | 
 | ||||||
|         if (!$apiKey) { |         if (!$apiKey) { | ||||||
|             throw new \InvalidArgumentException('API key is required'); |             throw new \InvalidArgumentException('API key is required'); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|         $this->apiKey = $apiKey; |         $this->apiKey = $apiKey; | ||||||
| 
 | 
 | ||||||
|         $apiSecret = $options['apiSecret'] ?? getenv('MULTI_DOWNLOADER_SECRET_KEY'); |         $apiSecret = $options['apiSecret'] ?? getenv('MULTI_DOWNLOADER_SECRET_KEY'); | ||||||
|  | 
 | ||||||
|         if (!$apiSecret) { |         if (!$apiSecret) { | ||||||
|             throw new \InvalidArgumentException('API secret key is required'); |             throw new \InvalidArgumentException('API secret key is required'); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|         $this->apiSecret = $apiSecret; |         $this->apiSecret = $apiSecret; | ||||||
| 
 | 
 | ||||||
|         $this->url = $options['url'] ?? getenv('MULTI_DOWNLOADER_URL') ?: 'https://multi-dl.kub.nwb.fr'; |         $this->url = $options['url'] ?? getenv('MULTI_DOWNLOADER_URL') ?: 'https://multi-dl.kub.nwb.fr'; | ||||||
|  | |||||||
| @ -16,8 +16,10 @@ class MultiDownloaderClientTest extends TestCase | |||||||
|     private function testFiles() |     private function testFiles() | ||||||
|     { |     { | ||||||
|         return array_map(function ($url, $i) { |         return array_map(function ($url, $i) { | ||||||
|             return (new FileRequest($url)) |             $file = new FileRequest($url); | ||||||
|                 ->fileOptions(['name' => 'test' . $i . '.png']); |             $file->getFileOptions()->name('test' . $i . '.png'); | ||||||
|  | 
 | ||||||
|  |             return $file; | ||||||
|         }, $this->testFiles, array_keys($this->testFiles)); |         }, $this->testFiles, array_keys($this->testFiles)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -38,7 +40,7 @@ class MultiDownloaderClientTest extends TestCase | |||||||
|     { |     { | ||||||
|         $client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']); |         $client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']); | ||||||
| 
 | 
 | ||||||
|         $path = __DIR__  . '/testDownloadTo.zip'; |         $path = sys_get_temp_dir() . '/testDownloadTo.zip'; | ||||||
| 
 | 
 | ||||||
|         $client->setFiles($this->testFiles()); |         $client->setFiles($this->testFiles()); | ||||||
|         $client->downloadTo($path); |         $client->downloadTo($path); | ||||||
|  | |||||||
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user