complete() public méthode

Complete
public complete ( $callback )
$callback
 protected function pushWithTemplate(SendCloudMessage $message, $template, array $data)
 {
     // 构造参数
     // 如果 不使用 maillist
     if (empty($message->maillist())) {
         if (empty($data)) {
             // 不需要模板数据, 构造无用填充数据
             $data = ['nothing' => $message->to()];
         }
         $param = $this->buildParamWithMessage($message, ['use_maillist' => 'false', 'substitution_vars' => json_encode(['to' => $message->to(), 'sub' => $data]), 'template_invoke_name' => $template]);
     } else {
         $param = $this->buildParamWithMessage($message, ['use_maillist' => 'true', 'to' => implode(';', $message->maillist()), 'template_invoke_name' => $template]);
     }
     $curl = new Curl();
     // 发送回调
     $curl->complete(function (Curl $instance) {
         $this->checkError($instance);
     });
     // 发送
     $curl->post(self::API_MAIL_SEND_TEMPLATE, $param);
     return $this;
 }
<?php

require '../src/Curl/Curl.php';
use Curl\Curl;
$curl = new Curl();
$curl->progress(function ($client, $download_size, $downloaded, $upload_size, $uploaded) {
    if ($download_size === 0) {
        return;
    }
    // Display a progress bar: xxx% [=======>             ]
    $progress_size = 40;
    $fraction_downloaded = $downloaded / $download_size;
    $dots = round($fraction_downloaded * $progress_size);
    printf('%3.0f%% [', $fraction_downloaded * 100);
    $i = 0;
    for (; $i < $dots - 1; $i++) {
        echo '=';
    }
    echo '>';
    for (; $i < $progress_size - 1; $i++) {
        echo ' ';
    }
    echo ']' . "\r";
});
$curl->complete(function ($instance) {
    echo "\n" . 'download complete' . "\n";
});
$curl->download('https://php.net/distributions/manual/php_manual_en.html.gz', '/tmp/php_manual_en.html.gz');
Exemple #3
0
 /**
  * Make a request
  * @param string $route the route to call
  * @return Curl
  * @throws ApiException
  */
 protected static function request($route = '')
 {
     $accessToken = self::getAccessToken();
     $curl = new Curl();
     $curl->base_url = $accessToken->url . ($route != '' ? $route : '');
     $curl->setHeader('Authorization', $accessToken->token);
     $curl->complete(function () use($curl) {
         $curl->close();
     });
     $curl->error(function () use($curl) {
         $message = is_object($curl->response) ? $curl->response->message : $curl->error_message;
         throw new ApiException($message);
     });
     return $curl;
 }