|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Gitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Gitamin\Handlers\Events\Project; |
|
13
|
|
|
|
|
14
|
|
|
use Gitamin\Events\Project\ProjectEventInterface; |
|
15
|
|
|
use Gitamin\Events\Project\ProjectWasRemovedEvent; |
|
16
|
|
|
use Gitamin\Events\Project\ProjectWasUpdatedEvent; |
|
17
|
|
|
use Gitamin\Models\Moment; |
|
18
|
|
|
use Gitamin\Models\Project; |
|
19
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
|
20
|
|
|
|
|
21
|
|
|
class SendProjectMomentHandler |
|
22
|
|
|
{ |
|
23
|
|
|
use DispatchesJobs; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Handle the project updated moment. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function handle(ProjectEventInterface $event) |
|
29
|
|
|
{ |
|
30
|
|
|
if ($event instanceof ProjectWasUpdatedEvent) { |
|
31
|
|
|
$action = Moment::UPDATED; |
|
32
|
|
|
} elseif ($event instanceof ProjectWasRemovedEvent) { |
|
33
|
|
|
$action = Moment::CLOSED; |
|
34
|
|
|
} else { |
|
35
|
|
|
$action = Moment::CREATED; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$this->trigger($event->project, $action); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Trigger the moment. |
|
43
|
|
|
* |
|
44
|
|
|
* @param \Gitamin\Models\Project $project |
|
45
|
|
|
* @param int $action |
|
46
|
|
|
*/ |
|
47
|
|
View Code Duplication |
protected function trigger(Project &$project, $action) |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
$data = [ |
|
50
|
|
|
'target_type' => 'Project', |
|
51
|
|
|
'target_id' => $project->id, |
|
|
|
|
|
|
52
|
|
|
'action' => $action, |
|
53
|
|
|
'author_id' => $project->creator_id, |
|
|
|
|
|
|
54
|
|
|
'project_id' => $project->id, |
|
|
|
|
|
|
55
|
|
|
]; |
|
56
|
|
|
$moment = Moment::create($data); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: