2323 * Download class for Playwright PHP.
2424 */
2525final class Download implements DownloadInterface
26- {
27- * @author Simon André <smn.andre@gmail.com>
28- */
29- final class Download implements DownloadInterface
3026{
3127 /**
3228 * @param array<string, mixed> $data
@@ -44,7 +40,6 @@ public function __construct(
4440 public function cancel (): void
4541 {
4642 $ this ->transport ->send ([
47- 'action ' => 'downloadCancel ' ,
4843 'action ' => 'download.cancel ' ,
4944 'downloadId ' => $ this ->downloadId ,
5045 ]);
@@ -73,16 +68,11 @@ public function createReadStream()
7368 rewind ($ stream );
7469
7570 return $ stream ;
76- public function createReadStream (): mixed
77- {
78- // TODO: Implement stream handling - PHP streams are different from Node.js Readable
79- return null ;
8071 }
8172
8273 public function delete (): void
8374 {
8475 $ this ->transport ->send ([
85- 'action ' => 'downloadDelete ' ,
8676 'action ' => 'download.delete ' ,
8777 'downloadId ' => $ this ->downloadId ,
8878 ]);
@@ -95,13 +85,6 @@ public function failure(): ?string
9585 'downloadId ' => $ this ->downloadId ,
9686 ]);
9787
98- $ error = $ response ['error ' ] ?? null ;
99-
100- return is_string ($ error ) ? $ error : null ;
101- 'action ' => 'download.failure ' ,
102- 'downloadId ' => $ this ->downloadId ,
103- ]);
104-
10588 if (isset ($ response ['error ' ]) && is_string ($ response ['error ' ])) {
10689 return $ response ['error ' ];
10790 }
@@ -126,24 +109,11 @@ public function path(): string
126109 }
127110
128111 return $ response ['path ' ];
129- public function path (): ?string
130- {
131- $ response = $ this ->transport ->send ([
132- 'action ' => 'download.path ' ,
133- 'downloadId ' => $ this ->downloadId ,
134- ]);
135-
136- if (isset ($ response ['path ' ]) && is_string ($ response ['path ' ])) {
137- return $ response ['path ' ];
138- }
139-
140- return null ;
141112 }
142113
143114 public function saveAs (string $ path ): void
144115 {
145116 $ this ->transport ->send ([
146- 'action ' => 'downloadSaveAs ' ,
147117 'action ' => 'download.saveAs ' ,
148118 'downloadId ' => $ this ->downloadId ,
149119 'path ' => $ path ,
@@ -152,13 +122,23 @@ public function saveAs(string $path): void
152122
153123 public function suggestedFilename (): string
154124 {
155- return $ this ->suggestedFilename ;
156- return is_string ($ this ->data ['suggestedFilename ' ] ?? null ) ? $ this ->data ['suggestedFilename ' ] : '' ;
125+ if ('' !== $ this ->suggestedFilename ) {
126+ return $ this ->suggestedFilename ;
127+ }
128+
129+ $ fallback = $ this ->data ['suggestedFilename ' ] ?? null ;
130+
131+ return is_string ($ fallback ) ? $ fallback : '' ;
157132 }
158133
159134 public function url (): string
160135 {
161- return $ this ->url ;
162- return is_string ($ this ->data ['url ' ] ?? null ) ? $ this ->data ['url ' ] : '' ;
136+ if ('' !== $ this ->url ) {
137+ return $ this ->url ;
138+ }
139+
140+ $ fallback = $ this ->data ['url ' ] ?? null ;
141+
142+ return is_string ($ fallback ) ? $ fallback : '' ;
163143 }
164144}
0 commit comments