Skip to content

Commit 28e071e

Browse files
committed
Merge tag 'v12.25.0'
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
2 parents e88bf1d + ff1e767 commit 28e071e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Pipeline.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
use Illuminate\Contracts\Container\Container;
77
use Illuminate\Contracts\Pipeline\Pipeline as PipelineContract;
88
use Illuminate\Support\Traits\Conditionable;
9+
use Illuminate\Support\Traits\Macroable;
910
use RuntimeException;
1011
use Throwable;
1112

1213
class Pipeline implements PipelineContract
1314
{
1415
use Conditionable;
16+
use Macroable;
1517

1618
/**
1719
* The container implementation.
@@ -48,6 +50,13 @@ class Pipeline implements PipelineContract
4850
*/
4951
protected $finally;
5052

53+
/**
54+
* Indicates whether to wrap the pipeline in a database transaction.
55+
*
56+
* @var string|null|\UnitEnum|false
57+
*/
58+
protected $withinTransaction = false;
59+
5160
/**
5261
* Create a new class instance.
5362
*
@@ -123,7 +132,9 @@ public function then(Closure $destination)
123132
);
124133

125134
try {
126-
return $pipeline($this->passable);
135+
return $this->withinTransaction !== false
136+
? $this->getContainer()->make('db')->connection($this->withinTransaction)->transaction(fn () => $pipeline($this->passable))
137+
: $pipeline($this->passable);
127138
} finally {
128139
if ($this->finally) {
129140
($this->finally)($this->passable);
@@ -245,6 +256,19 @@ protected function pipes()
245256
return $this->pipes;
246257
}
247258

259+
/**
260+
* Execute each pipeline step within a database transaction.
261+
*
262+
* @param string|null|\UnitEnum|false $withinTransaction
263+
* @return $this
264+
*/
265+
public function withinTransaction($withinTransaction = null)
266+
{
267+
$this->withinTransaction = $withinTransaction;
268+
269+
return $this;
270+
}
271+
248272
/**
249273
* Get the container instance.
250274
*

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
"require": {
1717
"php": "^8.3",
1818
"illuminate/contracts": "^13.0",
19+
"illuminate/macroable": "^13.0",
1920
"illuminate/support": "^13.0"
2021
},
2122
"autoload": {
2223
"psr-4": {
2324
"Illuminate\\Pipeline\\": ""
2425
}
2526
},
27+
"suggest": {
28+
"illuminate/database": "Required to use database transactions (^12.0)."
29+
},
2630
"extra": {
2731
"branch-alias": {
2832
"dev-master": "13.0.x-dev"

0 commit comments

Comments
 (0)