Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 47... Línea 47...
47
    protected $promise;
47
    protected $promise;
Línea 48... Línea 48...
48
 
48
 
49
    /** @var UploadState State used to manage the upload. */
49
    /** @var UploadState State used to manage the upload. */
Línea -... Línea 50...
-
 
50
    protected $state;
-
 
51
 
-
 
52
    /** @var bool Configuration used to indicate if upload progress will be displayed. */
50
    protected $state;
53
    protected $displayProgress;
51
 
54
 
52
    /**
55
    /**
53
     * @param Client $client
56
     * @param Client $client
54
     * @param array  $config
57
     * @param array  $config
55
     */
58
     */
56
    public function __construct(Client $client, array $config = [])
59
    public function __construct(Client $client, array $config = [])
57
    {
60
    {
58
        $this->client = $client;
61
        $this->client = $client;
59
        $this->info = $this->loadUploadWorkflowInfo();
62
        $this->info = $this->loadUploadWorkflowInfo();
-
 
63
        $this->config = $config + self::$defaultConfig;
-
 
64
        $this->state = $this->determineState();
-
 
65
 
-
 
66
        if (isset($config['display_progress'])
-
 
67
            && is_bool($config['display_progress'])
-
 
68
        ) {
60
        $this->config = $config + self::$defaultConfig;
69
            $this->displayProgress = $config['display_progress'];
Línea 61... Línea 70...
61
        $this->state = $this->determineState();
70
        }
62
    }
71
    }
63
 
72
 
Línea 86... Línea 95...
86
    /**
95
    /**
87
     * Upload the source asynchronously using multipart upload operations.
96
     * Upload the source asynchronously using multipart upload operations.
88
     *
97
     *
89
     * @return PromiseInterface
98
     * @return PromiseInterface
90
     */
99
     */
91
    public function promise()
100
    public function promise(): PromiseInterface
92
    {
101
    {
93
        if ($this->promise) {
102
        if ($this->promise) {
94
            return $this->promise;
103
            return $this->promise;
95
        }
104
        }
Línea 216... Línea 225...
216
    abstract protected function getCompleteParams();
225
    abstract protected function getCompleteParams();
Línea 217... Línea 226...
217
 
226
 
218
    /**
227
    /**
219
     * Based on the config and service-specific workflow info, creates a
228
     * Based on the config and service-specific workflow info, creates a
220
     * `Promise` for an `UploadState` object.
-
 
221
     *
-
 
222
     * @return PromiseInterface A `Promise` that resolves to an `UploadState`.
229
     * `Promise` for an `UploadState` object.
223
     */
230
     */
224
    private function determineState()
231
    private function determineState(): UploadState
225
    {
232
    {
226
        // If the state was provided via config, then just use it.
233
        // If the state was provided via config, then just use it.
227
        if ($this->config['state'] instanceof UploadState) {
234
        if ($this->config['state'] instanceof UploadState) {
228
            return $this->config['state'];
235
            return $this->config['state'];
Línea 238... Línea 245...
238
                    . 'your config for the MultipartUploader for '
245
                    . 'your config for the MultipartUploader for '
239
                    . $this->client->getApi()->getServiceFullName() . '.');
246
                    . $this->client->getApi()->getServiceFullName() . '.');
240
            }
247
            }
241
            $id[$param] = $this->config[$key];
248
            $id[$param] = $this->config[$key];
242
        }
249
        }
243
        $state = new UploadState($id);
250
        $state = new UploadState($id, $this->config);
244
        $state->setPartSize($this->determinePartSize());
251
        $state->setPartSize($this->determinePartSize());
Línea 245... Línea 252...
245
 
252
 
246
        return $state;
253
        return $state;
Línea 287... Línea 294...
287
    protected function getResultHandler(&$errors = [])
294
    protected function getResultHandler(&$errors = [])
288
    {
295
    {
289
        return function (callable $handler) use (&$errors) {
296
        return function (callable $handler) use (&$errors) {
290
            return function (
297
            return function (
291
                CommandInterface $command,
298
                CommandInterface $command,
292
                RequestInterface $request = null
299
                ?RequestInterface $request = null
293
            ) use ($handler, &$errors) {
300
            ) use ($handler, &$errors) {
294
                return $handler($command, $request)->then(
301
                return $handler($command, $request)->then(
295
                    function (ResultInterface $result) use ($command) {
302
                    function (ResultInterface $result) use ($command) {
296
                        $this->handleResult($command, $result);
303
                        $this->handleResult($command, $result);
297
                        return $result;
304
                        return $result;