@@ -6,10 +6,10 @@ |
||
| 6 | 6 | use function einfach\operation\response\isValidResponse; |
| 7 | 7 | use const einfach\operation\response\RESPONSE_TYPE_ERROR; |
| 8 | 8 | use const einfach\operation\response\RESPONSE_TYPE_OK; |
| 9 | -use einfach\operation\step\Step; |
|
| 10 | -use einfach\operation\step\Failure; |
|
| 11 | 9 | use einfach\operation\step\AbstractStep; |
| 12 | 10 | use einfach\operation\step\Always; |
| 11 | +use einfach\operation\step\Failure; |
|
| 12 | +use einfach\operation\step\Step; |
|
| 13 | 13 | use einfach\operation\step\TryCatch; |
| 14 | 14 | |
| 15 | 15 | class Railway |
@@ -33,6 +33,9 @@ discard block |
||
| 33 | 33 | $this->stepsQueue = []; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | + /** |
|
| 37 | + * @param string $stepName |
|
| 38 | + */ |
|
| 36 | 39 | protected function findTargetStepIndex($stepName) |
| 37 | 40 | { |
| 38 | 41 | $steps = array_column($this->stepsQueue, 'step'); |
@@ -161,6 +164,7 @@ discard block |
||
| 161 | 164 | |
| 162 | 165 | /** |
| 163 | 166 | * @throws \Exception |
| 167 | + * @param AbstractStep $step |
|
| 164 | 168 | */ |
| 165 | 169 | protected function performStep($step, &$params, $opt, $track) |
| 166 | 170 | { |
@@ -153,12 +153,12 @@ |
||
| 153 | 153 | $opt = $item['opt']; |
| 154 | 154 | /** |
| 155 | 155 | * @var $step AbstractStep |
| 156 | - */ |
|
| 156 | + */ |
|
| 157 | 157 | $track = $this->performStep($step, $params, $opt, $track); |
| 158 | 158 | |
| 159 | 159 | $failFast = $opt['failFast'] ?? null; |
| 160 | 160 | if($failFast && $track == self::TRACK_FAILURE) { |
| 161 | - break; |
|
| 161 | + break; |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | return new Result($params, $track, $this->signaturesPipeline); |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | protected function findTargetStepIndex($stepName) |
| 37 | 37 | { |
| 38 | 38 | $steps = array_column($this->stepsQueue, 'step'); |
| 39 | - $names = array_map(function ($step) { |
|
| 39 | + $names = array_map(function($step) { |
|
| 40 | 40 | return $step->name(); |
| 41 | 41 | }, $steps); |
| 42 | 42 | |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $track = $this->performStep($step, $params, $opt, $track); |
| 159 | 159 | |
| 160 | 160 | $failFast = $opt['failFast'] ?? null; |
| 161 | - if($failFast && $track == self::TRACK_FAILURE) { |
|
| 161 | + if ($failFast && $track == self::TRACK_FAILURE) { |
|
| 162 | 162 | break; |
| 163 | 163 | } |
| 164 | 164 | } |
@@ -69,7 +69,7 @@ |
||
| 69 | 69 | $stepResult = $result; |
| 70 | 70 | |
| 71 | 71 | if (is_a($result, Result::class)) { |
| 72 | - $stepResult = [ |
|
| 72 | + $stepResult = [ |
|
| 73 | 73 | 'params' => $result->params(), |
| 74 | 74 | 'type' => ($result->isSuccess()) ? RESPONSE_TYPE_OK : RESPONSE_TYPE_ERROR |
| 75 | 75 | ]; |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | public function railway() : Railway |
| 11 | 11 | { |
| 12 | 12 | return (new Railway) |
| 13 | - ->step(function ($params) { |
|
| 13 | + ->step(function($params) { |
|
| 14 | 14 | echo "Hey {$params['name']}. Say hello to anonymous function!"; |
| 15 | 15 | //return error($params, 'Early fail'); |
| 16 | 16 | return ok($params, ['newParam' => 'newValue']); |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | ->step([$this, 'nestedRailway']) |
| 19 | 19 | ->step([$this, 'castRequest'], ['name' => 'CastReq']) |
| 20 | 20 | ->step([$this, 'validateRequest']) |
| 21 | - ->step(function ($params) { |
|
| 21 | + ->step(function($params) { |
|
| 22 | 22 | return error($params, 'AAA!!!'); |
| 23 | 23 | }, ['failFast' => true]) |
| 24 | 24 | ->step([$this, 'findUser']) |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | ->tryCatch([$this, 'sendNotification']) |
| 28 | 28 | ->always([$this, 'writeLog']) |
| 29 | 29 | ->failure([$this, 'notifyAdmin'], ['name' => 'Last']) |
| 30 | - ->step(function ($params) { |
|
| 30 | + ->step(function($params) { |
|
| 31 | 31 | return ok($params, ['a' => 'b']); |
| 32 | 32 | }, ['after' => 'First', 'name' => 'FinalCheck']); |
| 33 | 33 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public function nestedRailway($params) |
| 46 | 46 | { |
| 47 | 47 | return (new Railway) |
| 48 | - ->step(function ($params) { |
|
| 48 | + ->step(function($params) { |
|
| 49 | 49 | //return error($params, 'Nested Railway failed!'); |
| 50 | 50 | return ok($params, ['nestedRwParam' => 'nestedRwValue']); |
| 51 | 51 | }) |