- $context = stream_context_create([],["notification" => function($notification, $severity, $message, $code, $bytes_cur, $bytes_max) {
- switch ($notification) {
- case STREAM_NOTIFY_CONNECT:
- $this->debug("\n");
- break;
- case STREAM_NOTIFY_PROGRESS:
- if ($bytes_max) {
- $bytes_pct = $bytes_cur/$bytes_max;
- $this->debug("\r %3d%% [%s>%s] ",
- $bytes_pct*100,
- str_repeat("=", round(70*$bytes_pct)),
- str_repeat(" ", round(70*(1-$bytes_pct)))
- );
- }
- break;
- case STREAM_NOTIFY_COMPLETED:
- /* this is not generated, why? */
- break;
+ /* print newline only once */
+ $done = false;
+ $task = new Task\StreamFetch($source, function($bytes_pct) use(&$done) {
+ if (!$done) {
+ $this->info(" %3d%% [%s>%s] \r",
+ floor($bytes_pct*100),
+ str_repeat("=", round(50*$bytes_pct)),
+ str_repeat(" ", round(50*(1-$bytes_pct)))
+ );
+ if ($bytes_pct == 1) {
+ $done = true;
+ printf("\n");
+ }