PHP 8.2.31
Preview: Create.php Size: 1.96 KB
/opt/cpanel/ea-wappspector/vendor/guzzlehttp/promises/src/Create.php

<?php

declare(strict_types=1);

namespace GuzzleHttp\Promise;

final class Create
{
    /**
     * Creates a promise for a value if the value is not a promise.
     *
     * @param mixed $value Promise or value.
     */
    public static function promiseFor($value): PromiseInterface
    {
        if ($value instanceof PromiseInterface) {
            return $value;
        }

        // Return a Guzzle promise that shadows the given promise.
        if (is_object($value) && method_exists($value, 'then')) {
            $wfn = method_exists($value, 'wait') ? [$value, 'wait'] : null;
            $cfn = method_exists($value, 'cancel') ? [$value, 'cancel'] : null;
            $promise = new Promise($wfn, $cfn);
            $value->then([$promise, 'resolve'], [$promise, 'reject']);

            return $promise;
        }

        return new FulfilledPromise($value);
    }

    /**
     * Creates a rejected promise for a reason if the reason is not a promise.
     * If the provided reason is a promise, then it is returned as-is.
     *
     * @param mixed $reason Promise or reason.
     */
    public static function rejectionFor($reason): PromiseInterface
    {
        if ($reason instanceof PromiseInterface) {
            return $reason;
        }

        return new RejectedPromise($reason);
    }

    /**
     * Create an exception for a rejected promise value.
     *
     * @param mixed $reason
     */
    public static function exceptionFor($reason): \Throwable
    {
        if ($reason instanceof \Throwable) {
            return $reason;
        }

        return new RejectionException($reason);
    }

    /**
     * Returns an iterator for the given value.
     *
     * @param mixed $value
     */
    public static function iterFor($value): \Iterator
    {
        if ($value instanceof \Iterator) {
            return $value;
        }

        if (is_array($value)) {
            return new \ArrayIterator($value);
        }

        return new \ArrayIterator([$value]);
    }
}

Directory Contents

Dirs: 0 × Files: 16

Name Size Perms Modified Actions
413 B lrw-r--r-- 2025-08-22 14:34:08
Edit Download
209 B lrw-r--r-- 2025-08-22 14:34:08
Edit Download
4.07 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download
1.96 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download
2.60 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download
7.42 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download
2.00 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download
941 B lrw-r--r-- 2025-08-22 14:34:08
Edit Download
8.75 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download
2.76 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download
249 B lrw-r--r-- 2025-08-22 14:34:08
Edit Download
2.21 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download
1.21 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download
1.97 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download
450 B lrw-r--r-- 2025-08-22 14:34:08
Edit Download
8.25 KB lrw-r--r-- 2025-08-22 14:34:08
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).