]> git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/PicoFarad/Request.php
PicoFarad framework for routing
[github/wallabag/wallabag.git] / inc / 3rdparty / PicoFarad / Request.php
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 }