|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Mark |
|
5
|
|
|
* Date: 05/04/2016 |
|
6
|
|
|
* Time: 14:13. |
|
7
|
|
|
* |
|
8
|
|
|
* Updated: 20/06/2016 00:56 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace App\Http\Controllers; |
|
12
|
|
|
|
|
13
|
|
|
use App\Model\Page; |
|
14
|
|
|
use App\Events\PageWasVisited; |
|
15
|
|
|
use App\Events\WebsiteWasVisited; |
|
16
|
|
|
use App\Classes\Repositories\MenuRepository; |
|
17
|
|
|
use App\Classes\Repositories\PageRepository; |
|
18
|
|
|
use App\Classes\Library\PageLoader\Frontpage; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class PageController. |
|
22
|
|
|
* |
|
23
|
|
|
* The class handles the page that will be sent back to the user. |
|
24
|
|
|
* |
|
25
|
|
|
* The FrontPageLoader class does all the work though. |
|
26
|
|
|
* |
|
27
|
|
|
* Errors are now handled in the ErrorController class. |
|
28
|
|
|
*/ |
|
29
|
|
|
class PageController extends Controller |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @var Page |
|
33
|
|
|
*/ |
|
34
|
|
|
private $currentPage; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* PageController constructor. |
|
38
|
|
|
* @param PageRepository $pages |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(PageRepository $pages) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->currentPage = $pages->whereName(currentURI()); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Redirects must use a controller to handle the parameter, as they require a specified target. |
|
47
|
|
|
* @return mixed |
|
|
|
|
|
|
48
|
|
|
*/ |
|
49
|
|
|
public function redirect() |
|
50
|
|
|
{ |
|
51
|
|
|
return redirect($this->currentPage->redirect->to(), 302); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Standard page views are once that use the URL as the designated target. |
|
56
|
|
|
* |
|
57
|
|
|
* @return mixed |
|
|
|
|
|
|
58
|
|
|
* @throws \Exception |
|
59
|
|
|
* @internal param FrontPageLoader $pageLoader |
|
60
|
|
|
*/ |
|
61
|
|
|
public function index() |
|
62
|
|
|
{ |
|
63
|
|
|
return (new Frontpage($this->currentPage, $this->navigationData()))->publish(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return mixed |
|
68
|
|
|
*/ |
|
69
|
|
|
private function navigationData() |
|
70
|
|
|
{ |
|
71
|
|
|
return app(MenuRepository::class)->allParentsWithChildren(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param Page $page |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
|
|
private function trackEvents(Page $page) |
|
79
|
|
|
{ |
|
80
|
|
|
event(new PageWasVisited($page)); |
|
81
|
|
|
|
|
82
|
|
|
event(new WebsiteWasVisited(request())); |
|
83
|
|
|
|
|
84
|
|
|
return true; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.