diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-07-11 17:06:51 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-07-11 17:06:51 +0200 |
commit | b3cda72e93fff3a4c3476e9e7e78ef2b2a3f02b9 (patch) | |
tree | fb23b73225da5bc3a4466a51915586f60dde802c /inc/3rdparty/PicoFarad/Request.php | |
parent | 3602405ec0dbc576fce09ff9e865ba2404622080 (diff) | |
download | wallabag-b3cda72e93fff3a4c3476e9e7e78ef2b2a3f02b9.tar.gz wallabag-b3cda72e93fff3a4c3476e9e7e78ef2b2a3f02b9.tar.zst wallabag-b3cda72e93fff3a4c3476e9e7e78ef2b2a3f02b9.zip |
PicoFarad framework for routing
Diffstat (limited to 'inc/3rdparty/PicoFarad/Request.php')
-rw-r--r-- | inc/3rdparty/PicoFarad/Request.php | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/inc/3rdparty/PicoFarad/Request.php b/inc/3rdparty/PicoFarad/Request.php new file mode 100644 index 00000000..46c82bca --- /dev/null +++ b/inc/3rdparty/PicoFarad/Request.php | |||
@@ -0,0 +1,78 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace PicoFarad\Request; | ||
4 | |||
5 | |||
6 | function param($name, $default_value = null) | ||
7 | { | ||
8 | return isset($_GET[$name]) ? $_GET[$name] : $default_value; | ||
9 | } | ||
10 | |||
11 | |||
12 | function int_param($name, $default_value = 0) | ||
13 | { | ||
14 | return isset($_GET[$name]) && ctype_digit($_GET[$name]) ? (int) $_GET[$name] : $default_value; | ||
15 | } | ||
16 | |||
17 | |||
18 | function value($name) | ||
19 | { | ||
20 | $values = values(); | ||
21 | return isset($values[$name]) ? $values[$name] : null; | ||
22 | } | ||
23 | |||
24 | |||
25 | function values() | ||
26 | { | ||
27 | if (! empty($_POST)) { | ||
28 | |||
29 | return $_POST; | ||
30 | } | ||
31 | |||
32 | $result = json_decode(body(), true); | ||
33 | |||
34 | if ($result) { | ||
35 | return $result; | ||
36 | } | ||
37 | |||
38 | return array(); | ||
39 | } | ||
40 | |||
41 | |||
42 | function body() | ||
43 | { | ||
44 | return file_get_contents('php://input'); | ||
45 | } | ||
46 | |||
47 | |||
48 | function file_content($field) | ||
49 | { | ||
50 | if (isset($_FILES[$field])) { | ||
51 | return file_get_contents($_FILES[$field]['tmp_name']); | ||
52 | } | ||
53 | |||
54 | return ''; | ||
55 | } | ||
56 | |||
57 | |||
58 | function file_info($field) | ||
59 | { | ||
60 | if (isset($_FILES[$field])) { | ||
61 | return array( | ||
62 | 'name' => $_FILES[$field]['name'], | ||
63 | 'mimetype' => $_FILES[$field]['type'], | ||
64 | 'size' => $_FILES[$field]['size'], | ||
65 | ); | ||
66 | } | ||
67 | |||
68 | return false; | ||
69 | } | ||
70 | |||
71 | |||
72 | function file_move($field, $destination) | ||
73 | { | ||
74 | if (isset($_FILES[$field]) && ! file_exists($destination)) { | ||
75 | @mkdir(dirname($destination), 0777, true); | ||
76 | move_uploaded_file($_FILES[$field]['tmp_name'], $destination); | ||
77 | } | ||
78 | } \ No newline at end of file | ||