Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
formatting
  • Loading branch information
taylorotwell committed Sep 15, 2025
commit 2a1bc6a1a8a7bda36a5dcd275f38864587d325ca
105 changes: 55 additions & 50 deletions src/Illuminate/Http/Client/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ class Batch
*/
protected $factory;

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

/**
* The list of requests.
*
Expand Down Expand Up @@ -55,25 +48,11 @@ class Batch
public $failedRequests = 0;

/**
* The date indicating when the batch was created.
*
* @var \Carbon\CarbonImmutable
*/
public $createdAt = null;

/**
* The date indicating when the batch was cancelled.
*
* @var \Carbon\CarbonImmutable|null
*/
public $cancelledAt = null;

/**
* The date indicating when the batch was finished.
* The handler function for the Guzzle client.
*
* @var \Carbon\CarbonImmutable|null
* @var callable
*/
public $finishedAt = null;
protected $handler;

/**
* The callback to run before the first request from the batch runs.
Expand Down Expand Up @@ -103,18 +82,44 @@ class Batch
*/
protected $thenCallback = null;

/**
* The date when the batch was created.
*
* @var \Carbon\CarbonImmutable
*/
public $createdAt = null;

/**
* The date when the batch was cancelled.
*
* @var \Carbon\CarbonImmutable|null
*/
public $cancelledAt = null;

/**
* The date when the batch was finished.
*
* @var \Carbon\CarbonImmutable|null
*/
public $finishedAt = null;

/**
* The callback to run after all the requests from the batch finish.
*
* @var \Closure|null
*/
protected $finallyCallback = null;

/**
* Create a new request batch instance.
*
* @return void
*/
public function __construct(?Factory $factory = null)
{
$this->factory = $factory ?: new Factory();
$this->factory = $factory ?: new Factory;
$this->handler = Utils::chooseHandler();
$this->createdAt = new CarbonImmutable();
$this->createdAt = new CarbonImmutable;
}

/**
Expand All @@ -130,30 +135,6 @@ public function as(string $key)
return $this->requests[$key] = $this->asyncRequest();
}

/**
* Retrieve the requests in the batch.
*
* @return array<array-key, \Illuminate\Http\Client\PendingRequest>
*/
public function getRequests(): array
{
return $this->requests;
}

/**
* Add a request to the batch with a numeric index.
*
* @param string $method
* @param array $parameters
* @return \Illuminate\Http\Client\PendingRequest|\GuzzleHttp\Promise\Promise
*/
public function __call(string $method, array $parameters)
{
$this->incrementPendingRequests();

return $this->requests[] = $this->asyncRequest()->$method(...$parameters);
}

/**
* Get the total number of requests that have been processed by the batch thus far.
*
Expand Down Expand Up @@ -425,4 +406,28 @@ protected function incrementFailedRequests(): void
{
$this->failedRequests++;
}

/**
* Get the requests in the batch.
*
* @return array<array-key, \Illuminate\Http\Client\PendingRequest>
*/
public function getRequests(): array
{
return $this->requests;
}

/**
* Add a request to the batch with a numeric index.
*
* @param string $method
* @param array $parameters
* @return \Illuminate\Http\Client\PendingRequest|\GuzzleHttp\Promise\Promise
*/
public function __call(string $method, array $parameters)
{
$this->incrementPendingRequests();

return $this->requests[] = $this->asyncRequest()->$method(...$parameters);
}
}