|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// namespace AnaxSERHTMLFORM; |
|
4
|
|
|
namespace Kifekenny\Comment\HTMLForm; |
|
5
|
|
|
|
|
6
|
|
|
use \Anax\HTMLForm\FormModel; |
|
7
|
|
|
use \Anax\DI\DIInterface; |
|
8
|
|
|
use \Kifekenny\Comment\Comment; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Example of FormModel implementation. |
|
12
|
|
|
*/ |
|
13
|
|
|
class Com2Session extends FormModel |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Constructor injects with DI container. |
|
17
|
|
|
* |
|
18
|
|
|
* @param Anax\DI\DIInterface $di a service container |
|
|
|
|
|
|
19
|
|
|
*/ |
|
20
|
2 |
|
public function __construct(DIInterface $dis) |
|
21
|
|
|
{ |
|
22
|
2 |
|
parent::__construct($dis); |
|
23
|
2 |
|
$this->form->create( |
|
24
|
|
|
[ |
|
25
|
2 |
|
"id" => __CLASS__, |
|
26
|
2 |
|
"legend" => "Set session", |
|
27
|
2 |
|
], |
|
28
|
|
|
[ |
|
29
|
|
|
"mail" => [ |
|
30
|
2 |
|
"type" => "text", |
|
31
|
2 |
|
"validation" => ["not_empty"], |
|
32
|
2 |
|
], |
|
33
|
|
|
"submit" => [ |
|
34
|
2 |
|
"type" => "submit", |
|
35
|
2 |
|
"value" => "Set session", |
|
36
|
2 |
|
"callback" => [$this, "callbackSubmit"] |
|
37
|
2 |
|
], |
|
38
|
|
|
] |
|
39
|
2 |
|
); |
|
40
|
2 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Callback for submit-button which should return true if it could |
|
46
|
|
|
* carry out its work and false if something failed. |
|
47
|
|
|
* |
|
48
|
|
|
* @return boolean true if okey, false if something went wrong. |
|
49
|
|
|
*/ |
|
50
|
|
|
public function callbackSubmit() |
|
51
|
|
|
{ |
|
52
|
|
|
// Get values from the submitted form |
|
53
|
|
|
$mail = $this->form->value("mail"); |
|
54
|
|
|
|
|
55
|
|
|
$session = $this->di->get("session"); |
|
56
|
|
|
|
|
57
|
|
|
if (!$mail) { |
|
58
|
|
|
$this->form->addOutput("Can't be empty"); |
|
59
|
|
|
return false; |
|
60
|
|
|
} |
|
61
|
|
|
$session->set("user_id", 1); |
|
62
|
|
|
$session->set("user_mail", $mail); |
|
63
|
|
|
$session->set("user_name", $mail); |
|
64
|
|
|
|
|
65
|
|
|
$this->form->addOutput("User was created."); |
|
66
|
|
|
return true; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.