Rule.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Builder;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * 审计规则
  7. *
  8. * @property int $id
  9. * @property int $type 类型:1-正则表达式、2-域名、3-IP、4-协议
  10. * @property string $name 规则描述
  11. * @property string $pattern 规则值
  12. * @property-read string $type_api_label
  13. * @property-read string $type_label
  14. * @method static Builder|Rule newModelQuery()
  15. * @method static Builder|Rule newQuery()
  16. * @method static Builder|Rule query()
  17. * @method static Builder|Rule whereId($value)
  18. * @method static Builder|Rule whereName($value)
  19. * @method static Builder|Rule wherePattern($value)
  20. * @method static Builder|Rule whereType($value)
  21. * @mixin \Eloquent
  22. */
  23. class Rule extends Model {
  24. public $timestamps = false;
  25. protected $table = 'rule';
  26. public function getTypeLabelAttribute(): string {
  27. switch($this->attributes['type']){
  28. case 1:
  29. $type_label = '正则表达式';
  30. break;
  31. case 2:
  32. $type_label = '域 名';
  33. break;
  34. case 3:
  35. $type_label = 'I P';
  36. break;
  37. case 4:
  38. $type_label = '协 议';
  39. break;
  40. default:
  41. $type_label = '未 知';
  42. }
  43. return $type_label;
  44. }
  45. public function getTypeApiLabelAttribute(): string {
  46. switch($this->attributes['type']){
  47. case 1:
  48. $type_api_label = 'reg';
  49. break;
  50. case 2:
  51. $type_api_label = 'domain';
  52. break;
  53. case 3:
  54. $type_api_label = 'ip';
  55. break;
  56. case 4:
  57. $type_api_label = 'protocol';
  58. break;
  59. default:
  60. $type_api_label = 'unknown';
  61. }
  62. return $type_api_label;
  63. }
  64. }