Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 50... Línea 50...
50
     *
50
     *
51
     * @param array|null    $queue       Array of responses, callables, or exceptions.
51
     * @param array|null    $queue       Array of responses, callables, or exceptions.
52
     * @param callable|null $onFulfilled Callback to invoke when the return value is fulfilled.
52
     * @param callable|null $onFulfilled Callback to invoke when the return value is fulfilled.
53
     * @param callable|null $onRejected  Callback to invoke when the return value is rejected.
53
     * @param callable|null $onRejected  Callback to invoke when the return value is rejected.
54
     */
54
     */
55
    public static function createWithMiddleware(array $queue = null, callable $onFulfilled = null, callable $onRejected = null): HandlerStack
55
    public static function createWithMiddleware(?array $queue = null, ?callable $onFulfilled = null, ?callable $onRejected = null): HandlerStack
56
    {
56
    {
57
        return HandlerStack::create(new self($queue, $onFulfilled, $onRejected));
57
        return HandlerStack::create(new self($queue, $onFulfilled, $onRejected));
58
    }
58
    }
Línea 59... Línea 59...
59
 
59
 
60
    /**
60
    /**
61
     * The passed in value must be an array of
61
     * The passed in value must be an array of
62
     * {@see \Psr\Http\Message\ResponseInterface} objects, Exceptions,
62
     * {@see ResponseInterface} objects, Exceptions,
63
     * callables, or Promises.
63
     * callables, or Promises.
64
     *
64
     *
65
     * @param array<int, mixed>|null $queue       The parameters to be passed to the append function, as an indexed array.
65
     * @param array<int, mixed>|null $queue       The parameters to be passed to the append function, as an indexed array.
66
     * @param callable|null          $onFulfilled Callback to invoke when the return value is fulfilled.
66
     * @param callable|null          $onFulfilled Callback to invoke when the return value is fulfilled.
67
     * @param callable|null          $onRejected  Callback to invoke when the return value is rejected.
67
     * @param callable|null          $onRejected  Callback to invoke when the return value is rejected.
68
     */
68
     */
69
    public function __construct(array $queue = null, callable $onFulfilled = null, callable $onRejected = null)
69
    public function __construct(?array $queue = null, ?callable $onFulfilled = null, ?callable $onRejected = null)
70
    {
70
    {
71
        $this->onFulfilled = $onFulfilled;
71
        $this->onFulfilled = $onFulfilled;
Línea 72... Línea 72...
72
        $this->onRejected = $onRejected;
72
        $this->onRejected = $onRejected;
Línea 136... Línea 136...
136
            function ($reason) use ($request, $options) {
136
            function ($reason) use ($request, $options) {
137
                $this->invokeStats($request, $options, null, $reason);
137
                $this->invokeStats($request, $options, null, $reason);
138
                if ($this->onRejected) {
138
                if ($this->onRejected) {
139
                    ($this->onRejected)($reason);
139
                    ($this->onRejected)($reason);
140
                }
140
                }
-
 
141
 
141
                return P\Create::rejectionFor($reason);
142
                return P\Create::rejectionFor($reason);
142
            }
143
            }
143
        );
144
        );
144
    }
145
    }
Línea 157... Línea 158...
157
                || $value instanceof PromiseInterface
158
                || $value instanceof PromiseInterface
158
                || \is_callable($value)
159
                || \is_callable($value)
159
            ) {
160
            ) {
160
                $this->queue[] = $value;
161
                $this->queue[] = $value;
161
            } else {
162
            } else {
162
                throw new \TypeError('Expected a Response, Promise, Throwable or callable. Found ' . Utils::describeType($value));
163
                throw new \TypeError('Expected a Response, Promise, Throwable or callable. Found '.Utils::describeType($value));
163
            }
164
            }
164
        }
165
        }
165
    }
166
    }
Línea 166... Línea 167...
166
 
167
 
Línea 197... Línea 198...
197
     * @param mixed $reason Promise or reason.
198
     * @param mixed $reason Promise or reason.
198
     */
199
     */
199
    private function invokeStats(
200
    private function invokeStats(
200
        RequestInterface $request,
201
        RequestInterface $request,
201
        array $options,
202
        array $options,
202
        ResponseInterface $response = null,
203
        ?ResponseInterface $response = null,
203
        $reason = null
204
        $reason = null
204
    ): void {
205
    ): void {
205
        if (isset($options['on_stats'])) {
206
        if (isset($options['on_stats'])) {
206
            $transferTime = $options['transfer_time'] ?? 0;
207
            $transferTime = $options['transfer_time'] ?? 0;
207
            $stats = new TransferStats($request, $response, $transferTime, $reason);
208
            $stats = new TransferStats($request, $response, $transferTime, $reason);