1: <?php
2:
3: namespace Deimos\Request;
4:
5: trait AdapterExtension
6: {
7:
8: use DefaultAdapter;
9:
10: private $allowMethods = [
11: 'attribute' => true,
12: 'get' => true,
13: 'query' => true,
14: 'post' => true,
15: 'data' => true,
16: 'put' => true,
17: 'patch' => true,
18: 'delete' => true,
19: ];
20:
21: 22: 23:
24: private $filters = [
25: 'int' => FILTER_VALIDATE_INT,
26: 'float' => FILTER_VALIDATE_FLOAT,
27: 'bool' => FILTER_VALIDATE_BOOLEAN,
28: 'email' => FILTER_VALIDATE_EMAIL,
29: 'ip' => FILTER_VALIDATE_IP,
30: 'url' => FILTER_VALIDATE_URL,
31: ];
32:
33: 34: 35:
36: private $defaults = [
37: 'int' => 0,
38: 'float' => .0,
39: 'bool' => false,
40: 'email' => '',
41: 'ip' => '',
42: 'url' => '',
43: ];
44:
45: 46: 47: 48: 49: 50: 51: 52:
53: public function __call($name, $arguments)
54: {
55: $parameters = preg_replace('~([A-Z])~', '_$1', $name, 1);
56:
57: $parameters = $this->normalizeLow($parameters);
58: list ($call, $filter) = explode('_', $parameters);
59:
60: if (empty($this->allowMethods[$call]))
61: {
62: throw new \BadFunctionCallException('Not found' . $name);
63: }
64:
65: if ($filter === 'unsafe')
66: {
67: $arguments[1] = isset($arguments[1]) ? $arguments[1] : null;
68: $arguments[2] = false;
69:
70: return call_user_func_array([$this, $call], $arguments);
71: }
72:
73: return $this->filterVariable(
74: call_user_func_array([$this, $call], $arguments),
75: $this->filters[$filter],
76: $this->defaults[$filter]
77: );
78: }
79:
80: }