Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Http/Client/Pool.php
Строк: 72
<?php

namespace IlluminateHttpClient;

use 
GuzzleHttpUtils;

/**
 * @mixin IlluminateHttpClientFactory
 */
class Pool
{
    
/**
     * The factory instance.
     *
     * @var IlluminateHttpClientFactory
     */
    
protected $factory;

    
/**
     * The handler function for the Guzzle client.
     *
     * @var callable
     */
    
protected $handler;

    
/**
     * The pool of requests.
     *
     * @var array
     */
    
protected $pool = [];

    
/**
     * Create a new requests pool.
     *
     * @param  IlluminateHttpClientFactory|null  $factory
     * @return void
     */
    
public function __construct(?Factory $factory null)
    {
        
$this->factory $factory ?: new Factory();
        
$this->handler Utils::chooseHandler();
    }

    
/**
     * Add a request to the pool with a key.
     *
     * @param  string  $key
     * @return IlluminateHttpClientPendingRequest
     */
    
public function as(string $key)
    {
        return 
$this->pool[$key] = $this->asyncRequest();
    }

    
/**
     * Retrieve a new async pending request.
     *
     * @return IlluminateHttpClientPendingRequest
     */
    
protected function asyncRequest()
    {
        return 
$this->factory->setHandler($this->handler)->async();
    }

    
/**
     * Retrieve the requests in the pool.
     *
     * @return array
     */
    
public function getRequests()
    {
        return 
$this->pool;
    }

    
/**
     * Add a request to the pool with a numeric index.
     *
     * @param  string  $method
     * @param  array  $parameters
     * @return IlluminateHttpClientPendingRequest|GuzzleHttpPromisePromise
     */
    
public function __call($method$parameters)
    {
        return 
$this->pool[] = $this->asyncRequest()->$method(...$parameters);
    }
}
Онлайн: 0
Реклама