|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Soap\LaravelWorkflowProcess; |
| 4 | + |
| 5 | +class WorkflowProcess |
| 6 | +{ |
| 7 | + private $configFile = 'workflow-process'; |
| 8 | + |
| 9 | + public function __construct() {} |
| 10 | + |
| 11 | + public function getAuthenticated() |
| 12 | + { |
| 13 | + $guards = config($this->configFile.'.authentication.guards', ['web']); |
| 14 | + $logic = config($this->configFile.'.authentication.logic', 'or'); |
| 15 | + |
| 16 | + if ($logic === 'and') { |
| 17 | + // The user is considered authenticated only if all guards return true. |
| 18 | + $authenticated = true; |
| 19 | + |
| 20 | + foreach ($guards as $guard) { |
| 21 | + if (! auth()->guard($guard)->check()) { |
| 22 | + $authenticated = false; |
| 23 | + break; |
| 24 | + } |
| 25 | + } |
| 26 | + } elseif ($logic === 'or') { |
| 27 | + $authenticated = false; |
| 28 | + foreach ($guards as $guard) { |
| 29 | + if (auth()->guard($guard)->check()) { |
| 30 | + $authenticated = true; |
| 31 | + break; |
| 32 | + } |
| 33 | + } |
| 34 | + } else { |
| 35 | + throw new \InvalidArgumentException('Invalid authentication logic. Use "and" or "or".'); |
| 36 | + } |
| 37 | + |
| 38 | + return $authenticated; |
| 39 | + } |
| 40 | + |
| 41 | + public function getUser() |
| 42 | + { |
| 43 | + $guards = config($this->configFile.'.authentication.guards', ['web']); |
| 44 | + $logic = config($this->configFile.'.authentication.logic', 'or'); |
| 45 | + |
| 46 | + if ($logic === 'and') { |
| 47 | + // The user is considered authenticated only if all guards return true. |
| 48 | + $user = null; |
| 49 | + |
| 50 | + foreach ($guards as $guard) { |
| 51 | + if (auth()->guard($guard)->check()) { |
| 52 | + $user = auth()->guard($guard)->user(); |
| 53 | + break; |
| 54 | + } |
| 55 | + } |
| 56 | + } elseif ($logic === 'or') { |
| 57 | + $user = null; |
| 58 | + foreach ($guards as $guard) { |
| 59 | + if (auth()->guard($guard)->check()) { |
| 60 | + $user = auth()->guard($guard)->user(); |
| 61 | + break; |
| 62 | + } |
| 63 | + } |
| 64 | + } else { |
| 65 | + throw new \InvalidArgumentException('Invalid authentication logic. Use "and" or "or".'); |
| 66 | + } |
| 67 | + |
| 68 | + return $user; |
| 69 | + } |
| 70 | +} |
0 commit comments