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\Http\Controllers; |
13
|
|
|
|
14
|
|
|
use Gitamin\Facades\Setting; |
15
|
|
|
use Gitamin\Models\Issue; |
16
|
|
|
use Gitamin\Models\ProjectNamespace; |
17
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown; |
18
|
|
|
use Illuminate\Routing\Controller; |
|
|
|
|
19
|
|
|
use Illuminate\Support\Str; |
20
|
|
|
use Roumen\Feed\Facades\Feed; |
21
|
|
|
|
22
|
|
|
class FeedController extends Controller |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Feed facade. |
26
|
|
|
* |
27
|
|
|
* @var \Roumen\Feed\Facades\Feed |
28
|
|
|
*/ |
29
|
|
|
protected $feed; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Create a new feed controller instance. |
33
|
|
|
* |
34
|
|
|
* @return void |
|
|
|
|
35
|
|
|
*/ |
36
|
|
|
public function __construct() |
37
|
|
|
{ |
38
|
|
|
$this->feed = Feed::make(); |
39
|
|
|
$this->feed->title = Setting::get('app_name'); |
40
|
|
|
$this->feed->description = trans('gitamin.feed'); |
41
|
|
|
$this->feed->link = Str::canonicalize(Setting::get('app_domain')); |
42
|
|
|
$this->feed->setDateFormat('datetime'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Generates an Atom feed of all issues. |
47
|
|
|
* |
48
|
|
|
* @param \Gitamin\Models\ProjectNamespace|null $namespace |
49
|
|
|
* |
50
|
|
|
* @return \Illuminate\Http\Response |
51
|
|
|
*/ |
52
|
|
|
public function atomAction(ProjectNamespace $namespace = null) |
53
|
|
|
{ |
54
|
|
|
return $this->feedAction($namespace, false); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Generates a Rss feed of all issues. |
59
|
|
|
* |
60
|
|
|
* @param \Gitamin\Models\ProjectNamespace|null $group |
|
|
|
|
61
|
|
|
* |
62
|
|
|
* @return \Illuminate\Http\Response |
63
|
|
|
*/ |
64
|
|
|
public function rssAction(ProjectNamespace $namespace = null) |
65
|
|
|
{ |
66
|
|
|
$this->feed->lang = Setting::get('app_locale'); |
|
|
|
|
67
|
|
|
|
68
|
|
|
return $this->feedAction($namespace, true); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Generates a feed of all issues. |
73
|
|
|
* |
74
|
|
|
* @param \Gitamin\Models\ProjectNamespace|null $namespace |
75
|
|
|
* @param bool $isRss |
76
|
|
|
* |
77
|
|
|
* @return \Illuminate\Http\Response |
78
|
|
|
*/ |
79
|
|
|
private function feedAction(ProjectNamespace &$namespace, $isRss) |
80
|
|
|
{ |
81
|
|
|
if ($namespace->exists) { |
82
|
|
|
$namespace->projects->map(function ($project) { |
83
|
|
|
$project->issues()->visible()->orderBy('created_at', 'desc')->get()->map(function ($issue) use ($isRss) { |
|
|
|
|
84
|
|
|
$this->feedAddItem($issue, $isRss); |
85
|
|
|
}); |
86
|
|
|
}); |
87
|
|
|
} else { |
88
|
|
|
Issue::visible()->orderBy('created_at', 'desc')->get()->map(function ($issue) use ($isRss) { |
|
|
|
|
89
|
|
|
$this->feedAddItem($issue, $isRss); |
90
|
|
|
}); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $this->feed->render($isRss ? 'rss' : 'atom'); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Adds an item to the feed. |
98
|
|
|
* |
99
|
|
|
* @param \Gitamin\Models\Issue $issue |
100
|
|
|
* @param bool $isRss |
101
|
|
|
*/ |
102
|
|
|
private function feedAddItem($issue, $isRss) |
103
|
|
|
{ |
104
|
|
|
$this->feed->add( |
|
|
|
|
105
|
|
|
$issue->name, |
|
|
|
|
106
|
|
|
Setting::get('app_name'), |
107
|
|
|
Str::canonicalize(route('issue', ['id' => $issue->id])), |
|
|
|
|
108
|
|
|
$isRss ? $issue->created_at->toRssString() : $issue->created_at->toAtomString(), |
|
|
|
|
109
|
|
|
$isRss ? $issue->message : Markdown::convertToHtml($issue->message) |
|
|
|
|
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: