Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 1... Línea 1...
1
<?php
1
<?php
Línea -... Línea 2...
-
 
2
 
-
 
3
declare(strict_types=1);
2
 
4
 
Línea 3... Línea 5...
3
namespace GuzzleHttp\Promise;
5
namespace GuzzleHttp\Promise;
4
 
6
 
5
final class Create
7
final class Create
6
{
8
{
7
    /**
9
    /**
8
     * Creates a promise for a value if the value is not a promise.
10
     * Creates a promise for a value if the value is not a promise.
9
     *
-
 
10
     * @param mixed $value Promise or value.
-
 
11
     *
11
     *
12
     * @return PromiseInterface
12
     * @param mixed $value Promise or value.
13
     */
13
     */
14
    public static function promiseFor($value)
14
    public static function promiseFor($value): PromiseInterface
15
    {
15
    {
16
        if ($value instanceof PromiseInterface) {
16
        if ($value instanceof PromiseInterface) {
Línea 21... Línea 21...
21
        if (is_object($value) && method_exists($value, 'then')) {
21
        if (is_object($value) && method_exists($value, 'then')) {
22
            $wfn = method_exists($value, 'wait') ? [$value, 'wait'] : null;
22
            $wfn = method_exists($value, 'wait') ? [$value, 'wait'] : null;
23
            $cfn = method_exists($value, 'cancel') ? [$value, 'cancel'] : null;
23
            $cfn = method_exists($value, 'cancel') ? [$value, 'cancel'] : null;
24
            $promise = new Promise($wfn, $cfn);
24
            $promise = new Promise($wfn, $cfn);
25
            $value->then([$promise, 'resolve'], [$promise, 'reject']);
25
            $value->then([$promise, 'resolve'], [$promise, 'reject']);
-
 
26
 
26
            return $promise;
27
            return $promise;
27
        }
28
        }
Línea 28... Línea 29...
28
 
29
 
29
        return new FulfilledPromise($value);
30
        return new FulfilledPromise($value);
Línea 32... Línea 33...
32
    /**
33
    /**
33
     * Creates a rejected promise for a reason if the reason is not a promise.
34
     * Creates a rejected promise for a reason if the reason is not a promise.
34
     * If the provided reason is a promise, then it is returned as-is.
35
     * If the provided reason is a promise, then it is returned as-is.
35
     *
36
     *
36
     * @param mixed $reason Promise or reason.
37
     * @param mixed $reason Promise or reason.
37
     *
-
 
38
     * @return PromiseInterface
-
 
39
     */
38
     */
40
    public static function rejectionFor($reason)
39
    public static function rejectionFor($reason): PromiseInterface
41
    {
40
    {
42
        if ($reason instanceof PromiseInterface) {
41
        if ($reason instanceof PromiseInterface) {
43
            return $reason;
42
            return $reason;
44
        }
43
        }
Línea 48... Línea 47...
48
 
47
 
49
    /**
48
    /**
50
     * Create an exception for a rejected promise value.
49
     * Create an exception for a rejected promise value.
51
     *
50
     *
52
     * @param mixed $reason
-
 
53
     *
-
 
54
     * @return \Exception|\Throwable
51
     * @param mixed $reason
55
     */
52
     */
56
    public static function exceptionFor($reason)
53
    public static function exceptionFor($reason): \Throwable
57
    {
54
    {
58
        if ($reason instanceof \Exception || $reason instanceof \Throwable) {
55
        if ($reason instanceof \Throwable) {
59
            return $reason;
56
            return $reason;
Línea 60... Línea 57...
60
        }
57
        }
61
 
58
 
Línea 62... Línea 59...
62
        return new RejectionException($reason);
59
        return new RejectionException($reason);
63
    }
60
    }
64
 
61
 
65
    /**
62
    /**
66
     * Returns an iterator for the given value.
-
 
67
     *
-
 
68
     * @param mixed $value
63
     * Returns an iterator for the given value.
69
     *
64
     *
70
     * @return \Iterator
65
     * @param mixed $value
71
     */
66
     */
72
    public static function iterFor($value)
67
    public static function iterFor($value): \Iterator
73
    {
68
    {