-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionController.php
70 lines (63 loc) · 1.43 KB
/
ActionController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
include_once dirname(__FILE__).'/../lib/Validation.php';
include_once dirname(__FILE__).'/../validationRules.php';
class ActionController
{
private $post;
private $get;
private $sess;
private $validationRules;
private $validator;
private $messages = array();
public function setParam ($post, $get, $sess)
{
$this->validator = new Validation;
$this->validationRules = new ValidationRules;
$this->post = $this->strp_tag ($post);
$this->get = $this->strp_tag ($get);
$this->sess = $sess;
$this->validate();
}
public function getMessages ()
{
return $this->messages;
}
public function getResult ()
{
return $this->get;
}
private function strp_tag ($array)
{
if (empty($array) || !is_array($array)) return array();
function my_filter (&$value, $key)
{
$value = strip_tags($value);
}
array_walk_recursive($array, 'my_filter');
return $array;
}
private function validate ()
{
if (!empty($this->post))
{
$this->getErrors ('post', $this->validationRules->getPostRules());
}
if (!empty($this->get))
{
$this->getErrors ('get', $this->validationRules->getGetRules());
}
}
private function getErrors ($req, $r)
{
$errors = $this->validator->validate ($this->$req, $r);
if (!empty($errors))
{
$this->messages[$req] = array();
foreach ($errors as $key => $error)
{
$k = explode(':', $error);
array_push($this->messages[$req], 'key:'.$k[0].' message:'.$k[1]);
}
}
}
}