-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormData.class.php
More file actions
124 lines (109 loc) · 3.02 KB
/
Copy pathFormData.class.php
File metadata and controls
124 lines (109 loc) · 3.02 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* FormData API
*
* Simulate HTML Form
*
* @package PHPHttpRequest
* @subpackage FormData
* @author qakcn <qakcnyn@gmail.com>
* @copyright 2015 qakcn
* @version 0.1
* @license http://mozilla.org/MPL/2.0/
* @link https://github.com/qakcn/PHPHttpRequest
*/
//namespace PHPHttpRequest;
class FormData {
private $member = array();
private $member_s = array();
private $member_p = array();
private $hasFile = false;
private $multipart = false;
/**
* append form member
*
* @param string $name "name" attribute
* @param string/File $value "value" attribute or File instance
* @param string $filename override File instance filename
* @return boolean false if $name is empty
* @access public
*/
public function append($name, $value, $filename = null) {
if(empty($name)) {
return false;
}
$m['name'] = $name;
if(is_a($value, 'File')) {
if(!empty((string)$filename)) {
$m['filename'] = (string)$filename;
}
$m['value'] = $value;
$this->hasFile = true;
}else {
$m['value'] = (string)$value;
}
array_push($this->member, $m);
return true;
}
/**
* getter, called when tring to get value of private properties
*
* @param string $name private property name, should be one of $valid
* @return mixed value of the property
* @access public
*/
public function __get($name) {
$valid = array('hasFile', 'multipart');
if(in_array($name, $valid)) {
return $this->$name;
}
return false;
}
/**
* setter, called when tring to set value of private properties
*
* @param string $name private property name, only 'multipart' allowed
* @param mixed $value value of the property, only boolean allowed for 'multipart'
* @access public
*/
public function __set($name, $value) {
if($name=='multipart') {
$this->$name = (bool)$value;
}
}
/**
* get first member of FormData and move it to buffer
*
* @return array first member of FormData
* @access public
*/
public function shift() {
if($m = array_shift($this->member)) {
array_push($this->member_s, $m);
return $m;
}
return false;
}
/**
* get last member of FormData and move it to buffer
*
* @return array last member of FormData
* @access public
*/
public function pop() {
if($m = array_pop($this->member)) {
array_unshift($this->member_p, $m);
return $m;
}
return false;
}
/**
* reset the members as never have used shift() or pop()
*
* @access public
*/
public function reset() {
$this->member = array_merge($this->member_s, $this->member, $this->member_p);
$this->member_s = $this->member_p = array();
}
}