本文整理汇总了PHP中CoreUtils::trim方法的典型用法代码示例。如果您正苦于以下问题:PHP CoreUtils::trim方法的具体用法?PHP CoreUtils::trim怎么用?PHP CoreUtils::trim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CoreUtils
的用法示例。
在下文中一共展示了CoreUtils::trim方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Processes a preference item's new value
*
* @param string $key
*
* @return mixed
*/
static function process($key)
{
$value = isset($_POST['value']) ? CoreUtils::trim($_POST['value']) : null;
switch ($key) {
case "cg_itemsperpage":
$thing = 'Color Guide items per page';
if (!is_numeric($value)) {
throw new \Exception("{$thing} must be a number");
}
$value = intval($value, 10);
if ($value < 7 || $value > 20) {
throw new \Exception("{$thing} must be between 7 and 20");
}
break;
case "p_vectorapp":
if (!empty($value) && !isset(CoreUtils::$VECTOR_APPS[$value])) {
throw new \Exception("The specified app is invalid");
}
break;
case "p_hidediscord":
case "p_disable_ga":
case "cg_hidesynon":
case "cg_hideclrinfo":
$value = $value ? 1 : 0;
break;
case "discord_token":
Response::fail("You cannot change the {$key} setting");
}
return $value;
}
示例2: process
/**
* Processes a configuration item's new value
*
* @param string $key
*
* @return mixed
*/
static function process($key)
{
$value = CoreUtils::trim($_POST['value']);
if ($value === '') {
return null;
}
switch ($key) {
case "reservation_rules":
case "about_reservations":
$value = CoreUtils::sanitizeHtml($value, $key === 'reservation_rules' ? array('li', 'ol') : array('p'));
break;
}
return $value;
}
示例3: __construct
/**
* Creates a class instance based on the settings provided
* All options are optional and have default fallbacks
*
* $o = array(
* // Prevents $ERROR_MISSING from being triggered
* Input::$IS_OPTIONAL => bool,
* // Throw exceptions instead of calling CoreUtils::Respond
* Input::$THROW_EXCEPTIONS => bool,
* // Range for length/size validation (choose one)
* Input::$IN_RANGE => [int], // input >= int
* Input::$IN_RANGE => [int1, int2], // input >= $mix && input <= $max
* Input::$IN_RANGE => [null, int], // input <= int
* // Custom error strings
* Input::$CUSTOM_ERROR_MESSAGES => array(
* Input::$ERROR_MISSING => string,
* Input::$ERROR_INVALID => string,
* Input::$ERROR_RANGE => string,
* 'custom' => string,
* )
* )
*
* @param string $key
* @param string $type
* @param array $o
*
* @return Input
*/
public function __construct($key, $type, $o = null)
{
if (isset($o[self::THROW_EXCEPTIONS])) {
$this->_respond = $o[self::THROW_EXCEPTIONS] === false;
}
if ($type instanceof RegExp) {
$this->_validator = function ($value) use($type) {
return $type->match($value) ? self::ERROR_NONE : self::ERROR_INVALID;
};
} else {
if (is_callable($type)) {
$this->_validator = $type;
} else {
if (empty(self::$SUPPORTED_TYPES[$type])) {
$this->_outputError('Input type is invalid');
}
}
}
$this->_type = $type;
if (!is_string($key)) {
$this->_outputError('Input key missing or invalid');
}
$this->_key = $key;
$this->_silentFail = isset($o[self::SILENT_FAILURE]) && $o[self::SILENT_FAILURE] === true;
$this->_source = $SRC = isset($o[self::METHOD_GET]) && $o[self::METHOD_GET] === true ? '_GET' : '_POST';
$_SRC = $GLOBALS[$SRC];
if (!isset($_SRC[$key]) || CoreUtils::length($_SRC[$key]) === 0) {
$result = empty($o[self::IS_OPTIONAL]) ? self::ERROR_MISSING : self::ERROR_NONE;
} else {
$this->_value = $this->_type === 'text' ? CoreUtils::trim($_SRC[$key], true) : CoreUtils::trim($_SRC[$key]);
$this->_origValue = $this->_value;
$this->_range = $o[self::IN_RANGE] ?? null;
$result = $this->_validate();
}
if ($result !== self::ERROR_NONE) {
$this->_outputError(!empty($o[self::CUSTOM_ERROR_MESSAGES][$result]) ? $o[self::CUSTOM_ERROR_MESSAGES][$result] : "Error wile checking \${$SRC}['{$this->_key}'] (code {$result})", $result);
}
}