Yeelight /
cloud2
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Yeelight\Traits; |
||||||
| 4 | |||||||
| 5 | use Illuminate\Database\Eloquent\Model; |
||||||
| 6 | use Yeelight\Models\Observers\BaseModelObserver; |
||||||
| 7 | |||||||
| 8 | /** |
||||||
| 9 | * Whenever a new model is saved for the first time, |
||||||
| 10 | * the creating and created events will fire. |
||||||
| 11 | * If a model already existed in the database and the save method is called, |
||||||
| 12 | * the updating / updated events will fire. |
||||||
| 13 | * However, in both cases, the saving / saved events will fire. |
||||||
| 14 | * |
||||||
| 15 | * @CREATE: saving > creating > created > saved |
||||||
| 16 | * @UPDATE: saving > updating > updated > saved |
||||||
| 17 | */ |
||||||
| 18 | trait BaseModelEvents |
||||||
| 19 | { |
||||||
| 20 | protected static function boot() |
||||||
| 21 | { |
||||||
| 22 | parent::boot(); |
||||||
| 23 | |||||||
| 24 | /** @var Model $ModelName */ |
||||||
| 25 | $ModelName = get_called_class(); |
||||||
| 26 | |||||||
| 27 | // Setup event bindings... |
||||||
| 28 | $ModelName::observe(new BaseModelObserver()); |
||||||
| 29 | } |
||||||
| 30 | |||||||
| 31 | public function onCreating() |
||||||
| 32 | { |
||||||
| 33 | |||||||
| 34 | // auto set user id |
||||||
| 35 | if ($this->autoUserId && empty($this->user_id)) { |
||||||
| 36 | $user_id = $this->getAuthUserId(); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 37 | if ($user_id > 0) { |
||||||
| 38 | $this->user_id = $user_id; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 39 | } |
||||||
| 40 | } |
||||||
| 41 | } |
||||||
| 42 | |||||||
| 43 | public function onCreated() |
||||||
| 44 | { |
||||||
| 45 | } |
||||||
| 46 | |||||||
| 47 | public function onUpdating() |
||||||
| 48 | { |
||||||
| 49 | } |
||||||
| 50 | |||||||
| 51 | public function onUpdated() |
||||||
| 52 | { |
||||||
| 53 | } |
||||||
| 54 | |||||||
| 55 | public function onSaving() |
||||||
| 56 | { |
||||||
| 57 | |||||||
| 58 | // update ips if true |
||||||
| 59 | if ($this->ips) { |
||||||
| 60 | $this->updateIps(); |
||||||
|
0 ignored issues
–
show
It seems like
updateIps() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 61 | } |
||||||
| 62 | |||||||
| 63 | // update users if true |
||||||
| 64 | if ($this->update_users) { |
||||||
| 65 | $this->updateUsers(); |
||||||
|
0 ignored issues
–
show
It seems like
updateUsers() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 66 | } |
||||||
| 67 | } |
||||||
| 68 | |||||||
| 69 | public function onSaved() |
||||||
| 70 | { |
||||||
| 71 | } |
||||||
| 72 | |||||||
| 73 | public function onDeleting() |
||||||
| 74 | { |
||||||
| 75 | } |
||||||
| 76 | |||||||
| 77 | public function onDeleted() |
||||||
| 78 | { |
||||||
| 79 | } |
||||||
| 80 | |||||||
| 81 | public function onRestoring() |
||||||
| 82 | { |
||||||
| 83 | } |
||||||
| 84 | |||||||
| 85 | public function onRestored() |
||||||
| 86 | { |
||||||
| 87 | } |
||||||
| 88 | } |
||||||
| 89 |