Last active
April 7, 2024 00:49
-
-
Save ilzrv/697dddbcb3dc6560f48cd5976a89b9c9 to your computer and use it in GitHub Desktop.
Laravel Pipeline and Hub Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Pipe1 | |
{ | |
public function handle($passable, Closure $next) | |
{ | |
$passable = ucfirst($passable); | |
return $next($passable); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Pipe2 | |
{ | |
public function handle($passable, Closure $next) | |
{ | |
$passable = $passable . ' - Pipe2!'; | |
return $next($passable); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Route::get('/hub', function () { | |
/** @var \Illuminate\Pipeline\Hub $hub */ | |
$hub = app(\Illuminate\Pipeline\Hub::class); | |
$hub->pipeline('awesome-hub-name', function ($pipeline, $object) { | |
return $pipeline | |
->send($object) | |
->through([ | |
Pipe1::class, | |
Pipe2::class, | |
]) | |
->thenReturn(); | |
}); | |
$hub->pipe('stringus', 'awesome-hub-name'); | |
}); | |
Route::get('/pipeline', function () { | |
/** @var \Illuminate\Pipeline\Pipeline $pipeline */ | |
$pipeline = app(\Illuminate\Pipeline\Pipeline::class); | |
$pipeline | |
->send('stringus!') | |
->through([ | |
Pipe1::class, | |
Pipe2::class, | |
]) | |
->thenReturn(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment