Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * class for managing a http request | |
38 | * | |
39 | */ | |
40 | class CRM_Utils_Request { | |
41 | ||
6a488035 TO |
42 | /** |
43 | * Retrieve a value from the request (GET/POST/REQUEST) | |
44 | * | |
a3379cc1 AH |
45 | * @param string $name |
46 | * Name of the variable to be retrieved. | |
47 | * @param string $type | |
48 | * Type of the variable (see CRM_Utils_Type for details). | |
49 | * @param object $store | |
50 | * Session scope where variable is stored. | |
51 | * @param bool $abort | |
52 | * TRUE, if the variable is required. | |
53 | * @param mixed $default | |
54 | * Default value of the variable if not present. | |
55 | * @param string $method | |
56 | * Where to look for the variable - 'GET', 'POST' or 'REQUEST'. | |
6a488035 | 57 | * |
a3379cc1 AH |
58 | * @return mixed |
59 | * The value of the variable | |
6a488035 | 60 | */ |
00be9182 | 61 | public static function retrieve($name, $type, &$store = NULL, $abort = FALSE, $default = NULL, $method = 'REQUEST') { |
6a488035 TO |
62 | |
63 | // hack to detect stuff not yet converted to new style | |
64 | if (!is_string($type)) { | |
65 | CRM_Core_Error::backtrace(); | |
66 | CRM_Core_Error::fatal(ts("Please convert retrieve call to use new function signature")); | |
67 | } | |
68 | ||
69 | $value = NULL; | |
70 | switch ($method) { | |
71 | case 'GET': | |
72 | $value = CRM_Utils_Array::value($name, $_GET); | |
73 | break; | |
74 | ||
75 | case 'POST': | |
76 | $value = CRM_Utils_Array::value($name, $_POST); | |
77 | break; | |
78 | ||
79 | default: | |
80 | $value = CRM_Utils_Array::value($name, $_REQUEST); | |
81 | break; | |
82 | } | |
83 | ||
84 | if (isset($value) && | |
85 | (CRM_Utils_Type::validate($value, $type, $abort, $name) === NULL) | |
86 | ) { | |
87 | $value = NULL; | |
88 | } | |
89 | ||
90 | if (!isset($value) && $store) { | |
91 | $value = $store->get($name); | |
92 | } | |
93 | ||
94 | if (!isset($value) && $abort) { | |
95 | CRM_Core_Error::fatal(ts("Could not find valid value for %1", array(1 => $name))); | |
96 | } | |
97 | ||
98 | if (!isset($value) && $default) { | |
99 | $value = $default; | |
100 | } | |
101 | ||
102 | // minor hack for action | |
103 | if ($name == 'action' && is_string($value)) { | |
104 | $value = CRM_Core_Action::resolve($value); | |
105 | } | |
106 | ||
107 | if (isset($value) && $store) { | |
108 | $store->set($name, $value); | |
109 | } | |
110 | ||
111 | return $value; | |
112 | } | |
ba56a28f TO |
113 | |
114 | /** | |
115 | * This is a replacement for $_REQUEST which includes $_GET/$_POST | |
116 | * but excludes $_COOKIE / $_ENV / $_SERVER. | |
117 | * | |
ba56a28f | 118 | * @return array |
ba56a28f | 119 | */ |
00be9182 | 120 | public static function exportValues() { |
ba56a28f TO |
121 | // For more discussion of default $_REQUEST handling, see: |
122 | // http://www.php.net/manual/en/reserved.variables.request.php | |
123 | // http://www.php.net/manual/en/ini.core.php#ini.request-order | |
124 | // http://www.php.net/manual/en/ini.core.php#ini.variables-order | |
125 | ||
126 | $result = array(); | |
127 | if ($_GET) { | |
128 | $result = array_merge($result, $_GET); | |
129 | } | |
130 | if ($_POST) { | |
131 | $result = array_merge($result, $_POST); | |
132 | } | |
133 | return $result; | |
134 | } | |
96025800 | 135 | |
6a488035 | 136 | } |