Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Http\Client;
4
 
5
use GuzzleHttp\Utils;
6
 
7
/**
8
 * @mixin \Illuminate\Http\Client\Factory
9
 */
10
class Pool
11
{
12
    /**
13
     * The factory instance.
14
     *
15
     * @var \Illuminate\Http\Client\Factory
16
     */
17
    protected $factory;
18
 
19
    /**
20
     * The handler function for the Guzzle client.
21
     *
22
     * @var callable
23
     */
24
    protected $handler;
25
 
26
    /**
27
     * The pool of requests.
28
     *
29
     * @var array
30
     */
31
    protected $pool = [];
32
 
33
    /**
34
     * Create a new requests pool.
35
     *
36
     * @param  \Illuminate\Http\Client\Factory|null  $factory
37
     * @return void
38
     */
39
    public function __construct(Factory $factory = null)
40
    {
41
        $this->factory = $factory ?: new Factory();
42
 
43
        if (method_exists(Utils::class, 'chooseHandler')) {
44
            $this->handler = Utils::chooseHandler();
45
        } else {
46
            $this->handler = \GuzzleHttp\choose_handler();
47
        }
48
    }
49
 
50
    /**
51
     * Add a request to the pool with a key.
52
     *
53
     * @param  string  $key
54
     * @return \Illuminate\Http\Client\PendingRequest
55
     */
56
    public function as(string $key)
57
    {
58
        return $this->pool[$key] = $this->asyncRequest();
59
    }
60
 
61
    /**
62
     * Retrieve a new async pending request.
63
     *
64
     * @return \Illuminate\Http\Client\PendingRequest
65
     */
66
    protected function asyncRequest()
67
    {
68
        return $this->factory->setHandler($this->handler)->async();
69
    }
70
 
71
    /**
72
     * Retrieve the requests in the pool.
73
     *
74
     * @return array
75
     */
76
    public function getRequests()
77
    {
78
        return $this->pool;
79
    }
80
 
81
    /**
82
     * Add a request to the pool with a numeric index.
83
     *
84
     * @param  string  $method
85
     * @param  array  $parameters
86
     * @return \Illuminate\Http\Client\PendingRequest
87
     */
88
    public function __call($method, $parameters)
89
    {
90
        return $this->pool[] = $this->asyncRequest()->$method(...$parameters);
91
    }
92
}