1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Forum\User; |
4
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
7
|
|
|
use Forum\Answer\Answer; |
8
|
|
|
use Forum\Comment\Comment; |
9
|
|
|
use Forum\Question\Question; |
10
|
|
|
use Forum\User\HTMLForm\UserLoginForm; |
11
|
|
|
use Forum\User\HTMLForm\CreateUserForm; |
12
|
|
|
|
13
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
14
|
|
|
// use Anax\Route\Exception\NotFoundException; |
15
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* A sample controller to show how a controller class can be implemented. |
19
|
|
|
*/ |
20
|
|
|
class UserController implements ContainerInjectableInterface |
21
|
|
|
{ |
22
|
|
|
use ContainerInjectableTrait; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var $data description |
28
|
|
|
*/ |
29
|
|
|
//private $data; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
|
33
|
|
|
// /** |
34
|
|
|
// * The initialize method is optional and will always be called before the |
35
|
|
|
// * target method/action. This is a convienient method where you could |
36
|
|
|
// * setup internal properties that are commonly used by several methods. |
37
|
|
|
// * |
38
|
|
|
// * @return void |
39
|
|
|
// */ |
40
|
|
|
// public function initialize() : void |
41
|
|
|
// { |
42
|
|
|
// ; |
43
|
|
|
// } |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Description. |
49
|
|
|
* |
50
|
|
|
* @param datatype $variable Description |
|
|
|
|
51
|
|
|
* |
52
|
|
|
* @throws Exception |
53
|
|
|
* |
54
|
|
|
* @return object as a response object |
55
|
|
|
*/ |
56
|
|
|
public function indexActionGet() : object |
57
|
|
|
{ |
58
|
|
|
$page = $this->di->get("page"); |
59
|
|
|
$user = new User(); |
60
|
|
|
$user->setDb($this->di->get("dbqb")); |
61
|
|
|
$page->add("user/login"); |
62
|
|
|
|
63
|
|
|
return $page->render([ |
64
|
|
|
"title" => "A index page", |
65
|
|
|
]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Description. |
72
|
|
|
* |
73
|
|
|
* @param datatype $variable Description |
|
|
|
|
74
|
|
|
* |
75
|
|
|
* @throws Exception |
76
|
|
|
* |
77
|
|
|
* @return object as a response object |
78
|
|
|
*/ |
79
|
|
|
public function loginAction() : object |
80
|
|
|
{ |
81
|
|
|
$page = $this->di->get("page"); |
82
|
|
|
$form = new UserLoginForm($this->di); |
83
|
|
|
$form->check(); |
84
|
|
|
$data = [ |
85
|
|
|
"form" => $form->getHTML(), |
86
|
|
|
"title" => "A login page", |
87
|
|
|
]; |
88
|
|
|
$page->add("user/login", $data); |
89
|
|
|
return $page->render($data); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Description. |
94
|
|
|
* |
95
|
|
|
* @param datatype $variable Description |
|
|
|
|
96
|
|
|
* |
97
|
|
|
* @throws Exception |
98
|
|
|
* |
99
|
|
|
* @return object as a response object |
100
|
|
|
*/ |
101
|
|
|
public function createAction() : object |
102
|
|
|
{ |
103
|
|
|
$page = $this->di->get("page"); |
104
|
|
|
$form = new CreateUserForm($this->di); |
105
|
|
|
//check gravatar |
106
|
|
|
//curl gravatar API |
107
|
|
|
$form->check(); |
108
|
|
|
|
109
|
|
|
$data = [ |
110
|
|
|
"form" => $form->getHTML(), |
111
|
|
|
"title" => "Create user" |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
$page->add("user/create", $data); |
115
|
|
|
return $page->render($data); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function viewAction($userId): object |
119
|
|
|
{ |
120
|
|
|
$page = $this->di->get("page"); |
121
|
|
|
$user = new User(); |
122
|
|
|
$question = new Question(); |
123
|
|
|
$answer = new Answer; |
124
|
|
|
$comment = new Comment; |
125
|
|
|
$user->setDb($this->di->get("dbqb")); |
126
|
|
|
$answer->setDb($this->di->get("dbqb")); |
127
|
|
|
$comment->setDb($this->di->get("dbqb")); |
128
|
|
|
$question->setDb($this->di->get("dbqb")); |
129
|
|
|
$user->findById($userId); |
130
|
|
|
$questions = $question->findAllWhere("user_id = ?", $userId); |
131
|
|
|
$comments = $comment->findAllWhere("user_id = ?", $userId); |
132
|
|
|
$answers = $answer->findAllWhere("user_id = ?", $userId); |
133
|
|
|
$data = [ |
134
|
|
|
"title" => $user->acronym, |
135
|
|
|
"user" => $user, |
136
|
|
|
"questions" => $questions, |
137
|
|
|
"comments" => $comments, |
138
|
|
|
"answers" => $answers, |
139
|
|
|
]; |
140
|
|
|
|
141
|
|
|
$page->add("user/view", $data); |
142
|
|
|
return $page->render($data); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.