3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
35 * Class for managing a http request
37 class CRM_Utils_Request
{
40 * Get a unique ID for the request.
42 * This unique ID is assigned to mysql when the connection is opened and is
45 * The intent is that it is available for logging purposes and for triggers.
47 * The resulting string is 17 characters long. This consists of 13 characters of uniqid
48 * and 4 more random characters.
50 * Uniqid is unique to the microsecond - to make it more unique we add 4 more characters
51 * but stop short of the full 23 character string that a prefix would generate.
53 * It is intended that this string will be saved to log tables so striking a balance between
54 * uniqueness and length is important. Note that I did check & lining up with byte values
55 * (e.g 16 characters) does not confer any benefits. Using a CHAR field rather than VARCHAR
56 * may improve speed, if indexed.
60 public static function id() {
61 if (!isset(\Civi
::$statics[__CLASS__
]['id'])) {
62 \Civi
::$statics[__CLASS__
]['id'] = uniqid() . CRM_Utils_String
::createRandom(CRM_Utils_String
::ALPHANUMERIC
, 4);
64 return \Civi
::$statics[__CLASS__
]['id'];
68 * Retrieve a value from the request (GET/POST/REQUEST)
71 * Name of the variable to be retrieved.
73 * Type of the variable (see CRM_Utils_Type for details).
74 * @param object $store
75 * Session scope where variable is stored.
77 * TRUE, if the variable is required.
78 * @param mixed $default
79 * Default value of the variable if not present.
80 * @param string $method
81 * Where to look for the variable - 'GET', 'POST' or 'REQUEST'.
84 * The value of the variable
86 public static function retrieve($name, $type, &$store = NULL, $abort = FALSE, $default = NULL, $method = 'REQUEST') {
88 // hack to detect stuff not yet converted to new style
89 if (!is_string($type)) {
90 CRM_Core_Error
::backtrace();
91 CRM_Core_Error
::fatal(ts("Please convert retrieve call to use new function signature"));
97 $value = self
::getValue($name, $_GET);
101 $value = self
::getValue($name, $_POST);
105 $value = self
::getValue($name, $_REQUEST);
110 (CRM_Utils_Type
::validate($value, $type, $abort, $name) === NULL)
115 if (!isset($value) && $store) {
116 $value = $store->get($name);
119 if (!isset($value) && $abort) {
120 CRM_Core_Error
::fatal(ts("Could not find valid value for %1", array(1 => $name)));
123 if (!isset($value) && $default) {
127 // minor hack for action
128 if ($name == 'action' && is_string($value)) {
129 $value = CRM_Core_Action
::resolve($value);
132 if (isset($value) && $store) {
133 $store->set($name, $value);
140 * @param string $name
141 * Name of the variable to be retrieved.
143 * @param array $method - '$_GET', '$_POST' or '$_REQUEST'.
146 * The value of the variable
148 public static function getValue($name, $method) {
149 if (isset($method[$name])) {
150 return $method[$name];
152 // CRM-18384 - decode incorrect keys generated when & is present in url
153 foreach ($method as $key => $value) {
154 if (strpos($key, 'amp;') !== FALSE) {
155 $method[str_replace('amp;', '', $key)] = $method[$key];
156 if (isset($method[$name])) {
157 return $method[$name];
168 * This is a replacement for $_REQUEST which includes $_GET/$_POST
169 * but excludes $_COOKIE / $_ENV / $_SERVER.
173 public static function exportValues() {
174 // For more discussion of default $_REQUEST handling, see:
175 // http://www.php.net/manual/en/reserved.variables.request.php
176 // http://www.php.net/manual/en/ini.core.php#ini.request-order
177 // http://www.php.net/manual/en/ini.core.php#ini.variables-order
181 $result = array_merge($result, $_GET);
184 $result = array_merge($result, $_POST);