linkeys-app /
signed-url
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Linkeys\UrlSigner\Middleware; |
||
| 4 | |||
| 5 | use Closure; |
||
| 6 | use Illuminate\Database\Eloquent\ModelNotFoundException; |
||
| 7 | use Illuminate\Support\Facades\Event; |
||
| 8 | use Linkeys\UrlSigner\Contracts\Models\Link; |
||
| 9 | use Linkeys\UrlSigner\Events\LinkClicked; |
||
| 10 | use Linkeys\UrlSigner\Exceptions\ClickLimit\LinkClickLimitReachedException; |
||
| 11 | use Linkeys\UrlSigner\Exceptions\ClickLimit\LinkGroupClickLimitReachedException; |
||
| 12 | use Linkeys\UrlSigner\Exceptions\Expiry\LinkExpiredException; |
||
| 13 | use Linkeys\UrlSigner\Exceptions\Expiry\LinkGroupExpiredException; |
||
| 14 | use Linkeys\UrlSigner\Exceptions\LinkNotFoundException; |
||
| 15 | use Linkeys\UrlSigner\Support\LinkRepository\LinkRepository; |
||
| 16 | use Symfony\Component\HttpFoundation\Request; |
||
| 17 | |||
| 18 | class CheckLinkValid |
||
| 19 | { |
||
| 20 | |||
| 21 | 11 | public function handle(Request $request, Closure $next) |
|
| 22 | { |
||
| 23 | |||
| 24 | 11 | $link = $request->get(\Linkeys\UrlSigner\Models\Link::class); |
|
| 25 | |||
| 26 | 11 | if($link->clickLimitReached()) { |
|
| 27 | 1 | throw new LinkClickLimitReachedException; |
|
| 28 | } |
||
| 29 | 10 | if($link->group && $link->group->clickLimitReached()) { |
|
| 30 | 1 | throw new LinkGroupClickLimitReachedException; |
|
| 31 | } |
||
| 32 | 9 | if($link->expired()) { |
|
| 33 | 3 | throw new LinkExpiredException; |
|
| 34 | } |
||
| 35 | |||
| 36 | 6 | if($link->group && $link->group->expired() && $link->expiry === null) { |
|
| 37 | 1 | throw new LinkGroupExpiredException; |
|
| 38 | } |
||
| 39 | |||
| 40 | 5 | Event::dispatch(new LinkClicked($link)); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 41 | |||
| 42 | 5 | return $next($request); |
|
| 43 | } |
||
| 44 | |||
| 45 | } |