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\Commands\Moment; |
13
|
|
|
|
14
|
|
|
use Gitamin\Commands\Moment\AddMomentCommand; |
15
|
|
|
use Gitamin\Dates\DateFactory; |
16
|
|
|
//use Gitamin\Events\Moment\MomentWasAddedEvent; |
17
|
|
|
use Gitamin\Models\Moment; |
18
|
|
|
|
19
|
|
|
class AddMomentCommandHandler |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* The date factory instance. |
23
|
|
|
* |
24
|
|
|
* @var \Gitamin\Dates\DateFactory |
25
|
|
|
*/ |
26
|
|
|
protected $dates; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Create a new report moment command handler instance. |
30
|
|
|
* |
31
|
|
|
* @param \Gitamin\Dates\DateFactory $dates |
32
|
|
|
* |
33
|
|
|
* @return void |
|
|
|
|
34
|
|
|
*/ |
35
|
|
|
public function __construct(DateFactory $dates) |
36
|
|
|
{ |
37
|
|
|
$this->dates = $dates; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Handle the report moment command. |
42
|
|
|
* |
43
|
|
|
* @param \Gitamin\Commands\Moment\AddMomentCommand $command |
44
|
|
|
* |
45
|
|
|
* @return \Gitamin\Models\Moment |
46
|
|
|
*/ |
47
|
|
|
public function handle(AddMomentCommand $command) |
48
|
|
|
{ |
49
|
|
|
$data = [ |
50
|
|
|
'action' => $command->action, |
51
|
|
|
'author_id' => $command->author_id, |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
if($command->title) { |
55
|
|
|
$data['title'] = $command->title; |
56
|
|
|
} |
57
|
|
|
if($command->data) { |
58
|
|
|
$data['data'] = $command->data; |
59
|
|
|
} |
60
|
|
|
// Link with the target. |
61
|
|
|
if ($command->target_type) { |
62
|
|
|
$data['target_type'] = $command->target_type; |
63
|
|
|
} |
64
|
|
|
if ($command->target_id) { |
65
|
|
|
$data['target_id'] = $command->target_id; |
66
|
|
|
} |
67
|
|
|
// Link with the project. |
68
|
|
|
if ($command->project_id) { |
69
|
|
|
$data['project_id'] = $command->project_id; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// Create the moment |
73
|
|
|
$moment = Moment::create($data); |
74
|
|
|
|
75
|
|
|
//event(new MomentWasAddedEvent($moment)); |
|
|
|
|
76
|
|
|
|
77
|
|
|
return $moment; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.