33namespace Neuron \Mvc \Requests ;
44
55use Neuron \Core \Exceptions \Validation ;
6+ use Neuron \Data \Filter \Get ;
7+ use Neuron \Data \Filter \Post ;
8+ use Neuron \Data \Filter \Server ;
9+ use Neuron \Data \Filter \Session ;
610use Neuron \Log \Log ;
11+ use Neuron \Routing \DefaultIpResolver ;
712use Neuron \Routing \RequestMethod ;
813use Symfony \Component \Yaml \Yaml ;
914
@@ -17,14 +22,79 @@ class Request
1722 private array $ _headers = [];
1823 private array $ _parameters ;
1924 private array $ _errors = [];
25+ private DefaultIpResolver $ _ipResolver ;
26+ private Get $ _get ;
27+ private Post $ _post ;
28+ private Server $ _server ;
29+ private Session $ _session ;
2030
2131 /**
2232 * Request constructor.
2333 */
2434 public function __construct ()
2535 {
36+ $ this ->_ipResolver = new DefaultIpResolver ();
37+ $ this ->_get = new Get ();
38+ $ this ->_post = new Post ();
39+ $ this ->_server = new Server ();
40+ $ this ->_session = new Session ();
2641 }
2742
43+ /**
44+ * @return string
45+ */
46+ public function getClientIp (): string
47+ {
48+ return $ this ->_ipResolver ->resolve ( $ _SERVER );
49+ }
50+
51+ /**
52+ * Filtered GET parameter
53+ * @param string $key
54+ * @param mixed|null $default
55+ * @return mixed
56+ */
57+ public function get ( string $ key , mixed $ default = null ): mixed
58+ {
59+ return $ this ->_get ->filterScalar ( $ key , $ default );
60+ }
61+
62+ /**
63+ * Filtered POST parameter
64+ * @param string $key
65+ * @param mixed|null $default
66+ * @return mixed
67+ */
68+ public function post ( string $ key , mixed $ default = null ): mixed
69+ {
70+ return $ this ->_post ->filterScalar ( $ key , $ default );
71+ }
72+
73+ /**
74+ * Filtered SERVER parameter
75+ * @param string $key
76+ * @param mixed|null $default
77+ * @return mixed
78+ */
79+ public function server ( string $ key , mixed $ default = null ): mixed
80+ {
81+ return $ this ->_server ->filterScalar ( $ key , $ default );
82+ }
83+
84+ /**
85+ *
86+ * @param string $key
87+ * @param mixed|null $default
88+ * @return mixed
89+ */
90+ public function session ( string $ key , mixed $ default = null ): mixed
91+ {
92+ return $ this ->_session ->filterScalar ( $ key , $ default );
93+ }
94+
95+ /**
96+ * @return array
97+ */
2898 public function getErrors (): array
2999 {
30100 return $ this ->_errors ;
0 commit comments