-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequest.php
More file actions
58 lines (56 loc) · 1.47 KB
/
Request.php
File metadata and controls
58 lines (56 loc) · 1.47 KB
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
<?php
class Request extends \Phalcon\Http\Request
{
/**
* @param null $name
* @param null $filters
* @return array
*/
public function getPatch($name=null, $filters=null) {
$items = [];
if($this->isPatch()) {
$filter = $this->getDI()->get('filter');
$params = $this->getArrayFromRawBody();
foreach($params as $k => $v) {
if($name && $name != $k) continue;
if($filters) {
if(is_array($filters)) {
foreach($filters as $f) $v = $filter->sanitize($v, $f);
} else {
$v = $filter->sanitize($v, $filters);
}
}
$items[$k] = $v;
}
}
return ($name) ? $items[$name] : $items;
}
/**
* @param $name
* @return bool
*/
public function hasPatch($name)
{
$has = false;
if($this->isPatch()) {
$params = $this->getArrayFromRawBody();
foreach($params as $k => $v) {
if($name && $name == $k) $has = true;
}
}
return $has;
}
/**
* @return array
*/
private function getArrayFromRawBody()
{
$items = [];
$raw = $this->getRawBody();
foreach(explode('&', $raw) as $pair) {
list($k, $v) = explode('=', $pair);
$items[$k] = $v;
}
return $items;
}
}