本文整理汇总了PHP中CString::trim方法的典型用法代码示例。如果您正苦于以下问题:PHP CString::trim方法的具体用法?PHP CString::trim怎么用?PHP CString::trim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CString
的用法示例。
在下文中一共展示了CString::trim方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: maybeUpdateThirdParty
/**
* @ignore
*/
public static function maybeUpdateThirdParty()
{
if (!self::isInCliMode()) {
// This method can be run in CLI mode only.
assert('false', vs(isset($this), get_defined_vars()));
return false;
}
$updates = CConfiguration::option("updates");
$updatesAreEnabled = $updates["enable"];
if ($updatesAreEnabled) {
$minTimeBetweenDoUpdatesDays = $updates["minTimeBetweenDoUpdatesDays"];
$components = $updates["components"];
assert('is_int($minTimeBetweenDoUpdatesDays)', vs(isset($this), get_defined_vars()));
// Logging.
$logging = $updates["logging"];
$loggingIsEnabled = $logging["enable"];
$logFp = $logging["logFilePath"];
if ($loggingIsEnabled) {
assert('!CString::isEmpty($logFp)', vs(isset($this), get_defined_vars()));
$logFp = CFilePath::frameworkPath($logFp);
CShell::setLogging($logFp);
}
// Mailing.
$mailing = $updates["mailing"];
$mailingIsEnabled = $mailing["enable"];
if ($mailingIsEnabled) {
$adminMail = CConfiguration::option("admin.mail");
$to = $adminMail["to"];
$from = $adminMail["from"];
$transport = $adminMail["transport"];
assert('!CString::isEmpty($to) && !CString::isEmpty($from) && !CString::isEmpty($transport)', vs(isset($this), get_defined_vars()));
$mail;
if (CString::equalsCi($transport, "smtp")) {
$smtpOutgoingServer = $adminMail["smtpOutgoingServer"];
$smtpUsername = $adminMail["smtpUsername"];
$smtpPassword = $adminMail["smtpPassword"];
assert('!CString::isEmpty($smtpOutgoingServer) && !CString::isEmpty($smtpUsername) && ' . '!CString::isEmpty($smtpPassword)', vs(isset($this), get_defined_vars()));
$mail = CMail::makeSmtp($smtpOutgoingServer, $smtpUsername, $smtpPassword, $from, $to);
} else {
if (CString::equalsCi($transport, "system")) {
$mail = CMail::makeSystem($from, $to);
} else {
assert('false', vs(isset($this), get_defined_vars()));
}
}
CShell::setMailing($mail);
}
$thirdPartyDp = $GLOBALS["PHRED_PATH_TO_THIRD_PARTY"];
$lastUpdateTimeFp = CFilePath::add($thirdPartyDp, self::$ms_thirdPartyLastUpdateTimeFn);
// Read the file containing the Unix seconds of the last update time stamp (if exists) and compare that
// time with the current time.
$numDaysSinceLastUpdate;
if (CFile::exists($lastUpdateTimeFp)) {
$lastUpdateTime = new CTime(CString::toInt(CFile::read($lastUpdateTimeFp)));
$currTime = CTime::now();
if ($lastUpdateTime->isBefore($currTime)) {
$numDaysSinceLastUpdate = $currTime->diffInDays($lastUpdateTime);
if ($numDaysSinceLastUpdate < $minTimeBetweenDoUpdatesDays) {
// It is too early for updates yet.
return false;
}
} else {
assert('false', vs(isset($this), get_defined_vars()));
}
}
$date = CShell::currentDate();
CShell::say("Started on {$date}.");
if (isset($numDaysSinceLastUpdate)) {
CShell::say("It has been {$numDaysSinceLastUpdate} day(s) since last successful update.");
}
$concurrLockFp = CFilePath::add($thirdPartyDp, self::$ms_thirdPartyConcurrLockFn);
// Try locking the operation.
if (!self::setLock($concurrLockFp, false)) {
assert('false', vs(isset($this), get_defined_vars()));
CShell::onError(false, "Could not obtain a lock on the operation.");
CShell::writeToLog("\n");
return false;
}
$phpConfigNeedsReload = false;
$totalNumComponents = CMap::length($components);
$numComponentsUpdated = 0;
// The Browser Capabilities Project (BrowsCap).
if (CMap::hasKey($components, "browsCap")) {
$browsCap = $components["browsCap"];
$skip = $browsCap["skip"];
if (!$skip) {
CShell::say("Updating the Browser Capabilities Project (BrowsCap) ...");
$lookupFileUrl = $browsCap["lookupFileUrl"];
assert('!CString::isEmpty($lookupFileUrl)', vs(isset($this), get_defined_vars()));
// Component-related constants.
static $s_configOptName = "browscap";
static $s_lookupFileDownloadTimeoutSeconds = 120;
if (self::hasConfigOption($s_configOptName)) {
$browsCapLookupFp = CString::trim(self::configOption($s_configOptName));
if (!CString::isEmpty($browsCapLookupFp)) {
$browsCapDp = CFilePath::directory($browsCapLookupFp);
CShell::say("Downloading a BrowsCap lookup file from '{$lookupFileUrl}' ...");
//.........这里部分代码省略.........
示例2: removeHeader
protected function removeHeader($headerName)
{
$headerName = CString::trim($headerName);
CArray::removeByValue($this->m_requestHeaders, $headerName, function ($element0, $element1) {
return CRegex::find($element0, "/^\\h*" . CRegex::enterTd($element1) . "\\h*:/i");
});
}
示例3: currentDate
/**
* Returns a string with the current date and time formatted by the shell to allow for consistency with other logs
* on the system.
*
* @return CUStringObject The current date and time formatted by the shell.
*/
public static function currentDate()
{
$date = self::execCommand("date");
$date = CString::trim($date);
return $date;
}
示例4: filter
/**
* Filters a string or a collection of strings according to the expected output type(s) and returns the output
* value(s).
*
* @param mixed $inputStringOrDecodedCollection The string to be filtered or the array or map containing the
* strings to be filtered. If the parameter's value is a JSON-encoded string, the output value is going to be
* either an array or map.
* @param reference $success **OUTPUT.** After the method is called, the value of this parameter tells whether
* the filtering was successful.
*
* @return mixed The output value or a collection of values of the expected type(s) after having been put through
* the filter.
*/
public function filter($inputStringOrDecodedCollection, &$success)
{
assert('is_cstring($inputStringOrDecodedCollection) || is_collection($inputStringOrDecodedCollection)', vs(isset($this), get_defined_vars()));
$success = true;
if ($this->m_expectedType != self::CARRAY && $this->m_expectedType != self::CMAP) {
// The expected output type is not a collection; the input value must be of string type.
if (!is_cstring($inputStringOrDecodedCollection)) {
$success = false;
return oop_x($this->m_defaultValue);
}
$inputString = $inputStringOrDecodedCollection;
if ($this->m_expectedType == self::BOOL || $this->m_expectedType == self::INT || $this->m_expectedType == self::FLOAT || $this->m_expectedType == self::EMAIL || $this->m_expectedType == self::URL || $this->m_expectedType == self::IP) {
// Trim the input string on both sides from whitespace, including Unicode whitespace and control
// characters.
$trimmingSubjectRe = CUString::TRIMMING_AND_SPACING_NORM_SUBJECT_RE;
$inputString = CRegex::remove($inputString, "/^({$trimmingSubjectRe})+|({$trimmingSubjectRe})+\\z/u");
}
// Pre-process the string for integer and floating-point types.
$looksLikeHex;
if ($this->m_expectedType == self::INT || $this->m_expectedType == self::FLOAT) {
if (CString::startsWith($inputString, "+")) {
// Remove the plus sign.
$inputString = CString::substr($inputString, 1);
}
$looksLikeHex = CRegex::find($inputString, "/^-?0x/i");
if ($this->m_allowLeadingZeros && !($this->m_expectedType == self::INT && $this->m_allowHex && $looksLikeHex)) {
// Remove any leading zeros (except for special cases).
$inputString = CRegex::replace($inputString, "/^(\\D*)0*(?!\\b)/", "\$1");
}
if ($this->m_allowComma) {
$inputString = CRegex::remove($inputString, "/,(?=\\d{3}\\b)/");
}
}
// Validate and sanitize the value according to its expected type.
if ($this->m_expectedType == self::BOOL) {
if (!CRegex::find($inputString, "/^(1|true|yes|on|0|false|no|off)\\z/i")) {
$success = false;
return $this->m_defaultValue;
}
return CString::equals($inputString, "1") || CString::equalsCi($inputString, "true") || CString::equalsCi($inputString, "yes") || CString::equalsCi($inputString, "on");
}
if ($this->m_expectedType == self::INT) {
$value;
if (!($this->m_allowHex && $looksLikeHex)) {
// Regular.
if (!CRegex::find($inputString, "/^-?(?!0(?!\\b))\\d+\\z/")) {
$success = false;
return $this->m_defaultValue;
}
$value = CString::toInt($inputString);
} else {
// Hex.
if (!CRegex::find($inputString, "/^-?0x[0-9A-F]+\\z/i")) {
$success = false;
return $this->m_defaultValue;
}
$value = CString::toIntFromHex($inputString);
}
if (isset($this->m_intValidMin) && $value < $this->m_intValidMin || isset($this->m_intValidMax) && $value > $this->m_intValidMax) {
$success = false;
return $this->m_defaultValue;
}
if (isset($this->m_intClampingMin) && $value < $this->m_intClampingMin) {
$value = $this->m_intClampingMin;
}
if (isset($this->m_intClampingMax) && $value > $this->m_intClampingMax) {
$value = $this->m_intClampingMax;
}
return $value;
}
if ($this->m_expectedType == self::FLOAT) {
if (!CRegex::find($inputString, "/^-?(?!0(?!\\b))\\d*\\.?\\d+(e[\\-+]?\\d+)?\\z/i")) {
$success = false;
return $this->m_defaultValue;
}
$value = CString::toFloat($inputString);
if (isset($this->m_floatValidMin) && $value < $this->m_floatValidMin || isset($this->m_floatValidMax) && $value > $this->m_floatValidMax) {
$success = false;
return $this->m_defaultValue;
}
if (isset($this->m_floatClampingMin) && $value < $this->m_floatClampingMin) {
$value = $this->m_floatClampingMin;
}
if (isset($this->m_floatClampingMax) && $value > $this->m_floatClampingMax) {
$value = $this->m_floatClampingMax;
}
return $value;
//.........这里部分代码省略.........