Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * class for managing a http request | |
38 | * | |
39 | */ | |
40 | class CRM_Utils_Request { | |
41 | ||
42 | /** | |
43 | * We only need one instance of this object. So we use the singleton | |
44 | * pattern and cache the instance in this variable | |
45 | * | |
46 | * @var object | |
47 | * @access private | |
48 | * @static | |
49 | */ | |
50 | static private $_singleton = NULL; | |
51 | ||
52 | /** | |
53 | * class constructor | |
450f494d | 54 | */ |
6a488035 TO |
55 | function __construct() {} |
56 | ||
57 | /** | |
58 | * Retrieve a value from the request (GET/POST/REQUEST) | |
59 | * | |
60 | * @param $name name of the variable to be retrieved | |
61 | * @param $type type of the variable (see CRM_Utils_Type for details) | |
62 | * @param $store session scope where variable is stored | |
63 | * @param $abort is this variable required | |
64 | * @param $default default value of the variable if not present | |
65 | * @param $method where should we look for the variable | |
66 | * | |
67 | * @return mixed the value of the variable | |
68 | * @access public | |
69 | * @static | |
70 | * | |
71 | */ | |
72 | static function retrieve($name, $type, &$store = NULL, $abort = FALSE, $default = NULL, $method = 'REQUEST') { | |
73 | ||
74 | // hack to detect stuff not yet converted to new style | |
75 | if (!is_string($type)) { | |
76 | CRM_Core_Error::backtrace(); | |
77 | CRM_Core_Error::fatal(ts("Please convert retrieve call to use new function signature")); | |
78 | } | |
79 | ||
80 | $value = NULL; | |
81 | switch ($method) { | |
82 | case 'GET': | |
83 | $value = CRM_Utils_Array::value($name, $_GET); | |
84 | break; | |
85 | ||
86 | case 'POST': | |
87 | $value = CRM_Utils_Array::value($name, $_POST); | |
88 | break; | |
89 | ||
90 | default: | |
91 | $value = CRM_Utils_Array::value($name, $_REQUEST); | |
92 | break; | |
93 | } | |
94 | ||
95 | if (isset($value) && | |
96 | (CRM_Utils_Type::validate($value, $type, $abort, $name) === NULL) | |
97 | ) { | |
98 | $value = NULL; | |
99 | } | |
100 | ||
101 | if (!isset($value) && $store) { | |
102 | $value = $store->get($name); | |
103 | } | |
104 | ||
105 | if (!isset($value) && $abort) { | |
106 | CRM_Core_Error::fatal(ts("Could not find valid value for %1", array(1 => $name))); | |
107 | } | |
108 | ||
109 | if (!isset($value) && $default) { | |
110 | $value = $default; | |
111 | } | |
112 | ||
113 | // minor hack for action | |
114 | if ($name == 'action' && is_string($value)) { | |
115 | $value = CRM_Core_Action::resolve($value); | |
116 | } | |
117 | ||
118 | if (isset($value) && $store) { | |
119 | $store->set($name, $value); | |
120 | } | |
121 | ||
122 | return $value; | |
123 | } | |
124 | } | |
125 |