| 1 | <?php |
||
| 9 | abstract class Component { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @var array |
||
| 13 | */ |
||
| 14 | protected $dontHandle = []; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * This array is overwritten in each component |
||
| 18 | * |
||
| 19 | * @var array |
||
| 20 | */ |
||
| 21 | protected $absolutelyDontHandle = []; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Determine if the exception is in the "do not handle" list. |
||
| 25 | * |
||
| 26 | * @param \Exception $e |
||
| 27 | * @return bool |
||
| 28 | */ |
||
| 29 | 12 | protected function shouldntHandle(Exception $e) { |
|
| 30 | 12 | $dontHandle = array_merge($this->dontHandle, $this->absolutelyDontHandle); |
|
| 31 | |||
| 32 | 12 | foreach ($dontHandle as $type) { |
|
| 33 | 12 | if ($e instanceof $type) { |
|
| 34 | 12 | return true; |
|
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | 12 | $sent_at = Cache::get($this->getCacheKey($e)); |
|
| 39 | 12 | if (empty($sent_at) || $sent_at->addSeconds(1)->lte(Carbon::now())) { |
|
| 40 | 12 | var_dump([$this->getCacheKey($e), $sent_at]); |
|
|
|
|||
| 41 | 12 | return false; // The cache is empty or enough time has passed |
|
| 42 | } else { |
||
| 43 | 3 | return true; |
|
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Returns the cache key for the exception with the current component |
||
| 49 | * |
||
| 50 | * @param \Exception $e |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | 12 | protected function getCacheKey(Exception $e) |
|
| 57 | } |