1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* GitScrum v0.1. |
4
|
|
|
* |
5
|
|
|
* @author Renato Marinho <[email protected]> |
6
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace GitScrum\Observers; |
10
|
|
|
|
11
|
|
|
use GitScrum\Models\ProductBacklog; |
12
|
|
|
use GitScrum\Models\Organization; |
13
|
|
|
use GitScrum\Classes\Helper; |
14
|
|
|
use Auth; |
15
|
|
|
|
16
|
|
|
class ProductBacklogObserver |
17
|
|
|
{ |
18
|
|
|
public function creating(ProductBacklog $productBacklog) |
19
|
|
|
{ |
20
|
|
|
if (!isset($productBacklog->user_id)) { |
21
|
|
|
$productBacklog->user_id = Auth::user()->id; |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$productBacklog->slug = Helper::slug($productBacklog->title); |
|
|
|
|
25
|
|
|
if (isset($productBacklog->is_api)) { |
26
|
|
|
$owner = Organization::find($productBacklog->organization_id); |
|
|
|
|
27
|
|
|
$productBacklog::$tmp = app(Auth::user()->provider)->createOrUpdateRepository($owner->username, $productBacklog); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function created(ProductBacklog $productBacklog) |
32
|
|
|
{ |
33
|
|
|
if (isset($productBacklog->is_api)) { |
34
|
|
|
$template = app(Auth::user()->provider)->tplRepository($productBacklog::$tmp, $productBacklog->slug); |
|
|
|
|
35
|
|
|
$obj = ProductBacklog::slug($template->slug)->first(); |
36
|
|
|
$obj->update(get_object_vars($template)); |
37
|
|
|
$productBacklog::$tmp = null; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function updating(ProductBacklog $productBacklog) |
42
|
|
|
{ |
43
|
|
|
$oldRepos = ProductBacklog::find($productBacklog->id); |
|
|
|
|
44
|
|
|
$owner = Organization::find($productBacklog->organization_id); |
|
|
|
|
45
|
|
|
$repos = app(Auth::user()->provider)->createOrUpdateRepository($owner->username, $productBacklog, $oldRepos->title); |
46
|
|
|
$productBacklog->html_url = $repos->html_url; |
|
|
|
|
47
|
|
|
$productBacklog->ssh_url = $repos->ssh_url; |
|
|
|
|
48
|
|
|
$productBacklog->clone_url = $repos->clone_url; |
|
|
|
|
49
|
|
|
$productBacklog->url = $repos->url; |
|
|
|
|
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.